Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int getSum(int n)
- {
- int sum = 0;
- while (n != 0)
- {
- sum = sum + n % 10;
- n = n/10;
- }
- return sum;
- }
- int main()
- {
- int n;
- printf("Please choose a number: ");
- scanf("%d",&n);
- printf("The sum of digits is: %d", getSum(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement