ahamed210

recursion3

Nov 5th, 2020
135
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.  
  3. //int c = 0;
  4.  
  5. void function(int n)
  6. {
  7.     static int b = 1, sum = 0;
  8.     if(b > n){
  9.         printf("%d\n", sum);
  10.         return;
  11.     }
  12.     sum+=b;
  13.     b++;
  14.     function(n);
  15. }
  16.  
  17. int main()
  18. {
  19.     int n;
  20.     scanf("%d", &n);
  21.     function(n);
  22.     return 0;
  23.     //main();
  24. }
Advertisement
Add Comment
Please, Sign In to add comment