Advertisement
AchkataJo

Untitled

Nov 21st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int getSum(int n)
  4. {
  5. int sum = 0;
  6. while (n != 0)
  7. {
  8. sum = sum + n % 10;
  9. n = n/10;
  10. }
  11. return sum;
  12. }
  13.  
  14. int main()
  15. {
  16. int n;
  17. printf("Please choose a number: ");
  18. scanf("%d",&n);
  19. printf("The sum of digits is: %d", getSum(n));
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement