Print Series Of Numbers Using Recursion in CPP
- Home
- Tutorials
- CPP
- CPP Programs
- Recursion
- Program
Source Code
#include <iostream>
using namespace std;
int printSeries ( int );
int main(int argc, char** argv) {
int a; // variable declaration for input
// Taking input in variables
cout<<"Enter First Number : ";
cin>>a;
//function call
cout<<printSeries(a);
return 0;
}
int printSeries ( int x) {
cout<<x<<endl;
x--;
if(x == 1) //base condition
return 1;
else
return printSeries(x); // recursive call
}
Output
Working
In this program example first of all a function is declared of name prnitSeries. Then in function defination ( after main function ) call to same method is palce in its own body. This call is called recursive call. A base condition is also set in function body which determine the end of recursion.