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]
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.
Use the following function: int gcd (int a, int b) { while (b != 0) { a %= b; a ^= b ^= a ^= b; } return a; } Note that a ^= b ^= a ^= b is an efficient method of swapping two values.
It gives you the sum of two or more numbers.
To write a C++ program to display the student details using class and array of object.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
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.
write a java program to find factorial using recursive and non recursive
i love u darling
Recursive refers to using a rule or procedure that can be applied repeatedly.
swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }
int SumOfDigit(int a) { if(a== 0) return 0; return (a%10 + SumOfDigit(a/10)); }
What alphabet are you using, and how are the natural numbers represented in this alphabet?
To write 24 January 2014 in 5 letters without using numbers kindly write 24.1.14.
4,900,000,000,000
No, Breadth-First Search (BFS) is not inherently recursive. It is typically implemented using a queue data structure rather than recursion.
thirty thousand
TODAY