Advertisement
Tariqul_Islam

Resursive digitsum

Jun 26th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,res;
  5.     scanf("%d",&n);
  6.     res=sum (n);
  7.     printf("%d",res);
  8. }
  9. int sum (int n)
  10. {
  11.     if(n==0)
  12.     {
  13.  
  14.         return 0;
  15.  
  16.     }
  17.     else
  18.     {
  19.         int rem,div;
  20.         rem=n%10;
  21.         div=n/10;
  22.         return rem+sum(div);
  23.     }
  24.  
  25.  
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement