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]
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
Write a recursive function in C to find sum of even numbers from 2 to 50?
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
(7 to 50).filter(_ % 2 == 0).sum
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
int SumOfDigit(int a) { if(a== 0) return 0; return (a%10 + SumOfDigit(a/10)); }
Recursive refers to using a rule or procedure that can be applied repeatedly.
swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }
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
using max function
#include<
function dec2bin($val){ if($val & 1){ $rval = '1'; }else{ $rval = '0'; } $val >>= 1; if($val > 0){ $rval = dec2bin($val) . $rval; } return $rval; }