Write a recursive void function that takes a single int argument n and
writes the integers 1, 2, …, n.
Recursive function:
//Recursive function of increaseCount:
//It takes a single int argument n and
//writes the integers 1, 2, …, n
void increaseCount( int n )
{
if (n >= 1)
{
increaseCount(n - 1);
cout <<n << " ";
}
}
Complete program by using above recursive function:
//Header section
#include <iostream>
using namespace std;
//Function prototype
void increaseCount(int n);
//main program
int main( )
{
//Call the method
cout<<"If the argument is 15,then the output: ";
increaseCount(15);
return 0;
}
//Recursive function of increaseCount:
//It takes a single int argument n and
//writes the integers 1, 2, …, n
void increaseCount( int n )
{
if (n >= 1)
{
increaseCount(n - 1);
cout <<n << " ";
}
}
Output of the program: