Advertisement
AedenCak3

C program to read an integer and compute the sum of digits

Nov 15th, 2021
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.23 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,m,sum=0;
  5.  
  6.     printf("enter a value: ");
  7.     scanf("%d", &n);
  8.  
  9.     while (n>0)
  10.     {
  11.       m=n%10;
  12.       sum=sum+m;
  13.       n/=10;
  14.     }
  15.      printf("%d", sum);
  16.  
  17.      
  18.   return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement