Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a program to add the digits of a number.
- Sample execution:
- Enter a number: 69837
- The sum of the digits of this number is: 33
- */
- #include<stdio.h>
- int main()
- {
- int rem,n,sum=0; /// rem=remaining
- printf("enter number: ");
- scanf("%d", &n);
- while(n>0)
- {
- rem=n%10;
- sum=sum+rem;
- n=n/10;
- }
- printf("sum of digits: %d", sum);
- }
- // input: 123
- // output: 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement