answersLogoWhite

0

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

16y ago

What else can I help you with?

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


How do you write a program to factorial in PHP?

To write a program that calculates the factorial of a number in PHP, you can use a recursive function or an iterative approach. Here’s a simple example using a loop: function factorial($n) { $result = 1; for ($i = 2; $i <= $n; $i++) { $result *= $i; } return $result; } echo factorial(5); // Outputs: 120 This code defines a function that multiplies numbers from 2 up to the given number $n to compute the factorial.


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

i love u darling


How do you put a recursive equation into a ti-84 calculator?

To input a recursive equation into a TI-84 calculator, you can use the "Seq" function. First, access the "Y=" menu, then define your recursive sequence by using the format Seq(Y1, n, start, end), where Y1 is your recursive formula, and "start" and "end" are the range of values for n. Alternatively, you can manually calculate the terms by iterating through the recursive formula using the calculator's programming feature or list functions.


Write a program to swap two numbers using function?

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


What does recursive mean?

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


Sum of digit using recursive function.?

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


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


Is BFS recursive?

No, Breadth-First Search (BFS) is not inherently recursive. It is typically implemented using a queue data structure rather than recursion.