Advertisement
LegoDrifter

Rekurzija suma na cifri

Jan 27th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include <stdio.h>
  2. int sumacifri (int n)
  3.     {
  4.      if(n==0)
  5.      return 0;
  6.      else
  7.      {
  8.      return((n%10)+sumacifri(n/10));
  9.      }
  10.     }
  11. int main()
  12.     {
  13.         int n;
  14.         scanf("%d",&n);
  15.         printf("%d\n",sumacifri(n));
  16.     return 0;
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement