Advertisement
Guest User

Untitled

a guest
May 5th, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. Write a recursive function to find sum of even numbers from 2 to 50 in c language
  2. int sumEvensRecursively(int no1, int no2)
  3. {
  4. no1=5;
  5. no2=20;
  6. if (no1 % 2 == 1)
  7. {
  8. return sumEvensRecursively(no1+ 1, no2);
  9. }
  10.  
  11. return no1+ sumEvensRecursively(no1+ 2, no2);
  12.  
  13. }
  14.  
  15. recur(int sum, int i){
  16. if(i <= 50){
  17. sum = sum + i;
  18. return recur(sum, (i+2));
  19.  
  20. }
  21. else
  22. return sum;
  23.  
  24. }
  25.  
  26. recur(0,2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement