Advertisement
muftY

Recursion Advnc camo. odd nmbr sum

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