Advertisement
ahamed210

recursion2

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