Advertisement
RIFATKHAN1

sum of digits of a number. - using while loop

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