Print Even Numbers using Recursion
Here we will learn to make a C++ program to print even numbers using recursion upto n numbers.
Even numbers meaning?
Even numbers are those numbers which can be completely divided by 2, and have not any remainder.
For example:
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 etc.
Example of C++ Program to Print Even Numbers using Recursion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> using namespace std; int a=0; int main() { int n,c; int even(int); cout<<"Enter number of terms :\n"; cin>>n; cout<<"\nSeries is :\n"; c=even(2*n); cout<<"\t"<<c; } int even(int n) { if(n==2) return 2; else { cout<<"\t"<<n; return (even(n-2)); } } |
Output
Enter number of terms :
10
Series is :
20 18 16 14 12 10 8 6 4 2
Check out our other C++ programming Examples