Advertisement
LegoDrifter

Rekurzija suma

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