fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n;
  5. printf("Enter the number: ");
  6. scanf("%d",&n);
  7. int sum=0;
  8. int lastdigit=0;
  9. while(n!=0){
  10. lastdigit= n%10;
  11. sum=sum + lastdigit;
  12. n=n/10;
  13. }
  14. printf("The sum of digits are %d",sum);
  15.  
  16.  
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0.01s 5280KB
stdin
1122
stdout
Enter the number: The sum of digits are 6