AquaBlitz11

[t006] sumdigit

Oct 9th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. #include <stdio.h>
  2. long DigitSum(long n1)
  3. {
  4.     if(n1 == 0)
  5.         return 0;
  6.     else
  7.     return ((n1 % 10) + DigitSum(n1 / 10));
  8. }
  9. int main()
  10. {
  11.     long n1, sum;
  12.     scanf("%ld", &n1);
  13.     sum = DigitSum(n1);
  14.     printf("%ld",sum);
  15.     return 0;
  16. }
Add Comment
Please, Sign In to add comment