keymasterviriya1150

1-N recursive

Nov 9th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. #include <stdio.h>
  2. int summ(int n);
  3. int main ()
  4. {
  5.     int i,n,c,b;
  6.     printf("N = ");
  7.     scanf("%d",&n);
  8.     c=summ(n);
  9.     printf("Sum = %d ",c);
  10. }
  11. int summ(int n)
  12. {
  13.     if(n==1)
  14.        return 1;
  15.    else
  16.        return n+summ(n-1);
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment