Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.41 KB  |  views: 184  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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);
clone this paste RAW Paste Data