Advertisement
Miti059

4.calculate sum of digits of anumber

Jun 23rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.19 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int num,sum=0,r;
  5. printf("enter any number:");
  6. scanf("%d",&num);
  7.  
  8. while(num!=0)
  9. {
  10. r=num%10;
  11. sum=sum+r;
  12. num=num/10;
  13. }
  14. printf("%d",sum);
  15. return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement