Advertisement
afrinahoque

Sum of digits of a number

Jun 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n, rem, sum=0;
  5. printf("Enter the number:");
  6. scanf("%d", &n);
  7. while (n!=0)
  8. {
  9. rem=n%10;
  10. sum=sum+rem;
  11. n=n/10;
  12. }
  13. printf("Sum of digits=%d", sum);
  14. return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement