answersLogoWhite

0


Best Answer

I can't imagine a useful reason to have a recursive function to find this, but here you go:

int sumEvens(int start, int end) {

// end condition

if (start > end) {

return 0;

}

// correction if we start on an odd number

if (start % 2 == 1) {

return sumEvens(start + 1, end);

}

// actual work

return start + sumEvens(start + 2, end);

}

Invoke with sumEvens(2, 50) to get the sum of all even numbers in the range [2,50]

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

int evensumrec(int *a, int n)

{

if(*(a+n)%2==0)

{

if(n>=0)

return (*(a+n)+evensumrec(a,n-1));

else

return 0;

}

else

return (evensumrec(a,n-1));

}

http://thecprojectt.blogspot.in/2012/12/c-program-3.html

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Write a recursive function in C to find sum of even numbers from 2 to 50?

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

1 and 50 = 51

2 and 49 = 51

3 and 48 = 51

etc

There are 25 such pairs, each adding to 51.

So the sum is 25*51 = 1275

This answer is:
User Avatar

User Avatar

Wiki User

5y ago

(7 to 50).filter(_ % 2 == 0).sum

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a recursive function to find sum of even numbers from 2 to 50 using C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

The efficiency of using recursive function rather than using ordinary function?

For some algorithms recursive functions are faster, and there are some problems that can only be solved through recursive means as iterative approaches are computationally infeasible.


Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


Write a c program to find GCD of two given integers by using both recursive n non recursive functions?

i love u darling


Sum of digit using recursive function.?

int SumOfDigit(int a) { if(a== 0) return 0; return (a%10 + SumOfDigit(a/10)); }


What does recursive mean?

Recursive refers to using a rule or procedure that can be applied repeatedly.


Write a program to swap two numbers using function?

swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }


Give a recursive definition for the language L of positive integers divisible by 2 or 7?

What alphabet are you using, and how are the natural numbers represented in this alphabet?


How do u write 24 January 2014 in 5 letters without using numbers?

To write 24 January 2014 in 5 letters without using numbers kindly write 24.1.14.


How do you write 4.9 trillion using numbers?

4,900,000,000,000


How do you compare 2 numbers without using relational operators in c?

using max function


Write a c program for matrix addition using function?

#include<


Convert decimal to binary using recursive function in php programming?

function dec2bin($val){ if($val & 1){ $rval = '1'; }else{ $rval = '0'; } $val >>= 1; if($val > 0){ $rval = dec2bin($val) . $rval; } return $rval; }