Write a recursive void function that has one parameter which is a positive
integer and that writes out that number of asterisks '*' to the screen all
on one line.
Recursive function definition:
//Recursive function of printAsterisks:
//It takes one parameter which is a positive integer and
//that writes out that number of asterisks '*'.
//This astrisks display to the screen all
//on one line.
void printAsterisks(int numOfAsterisks)
{
cout << '*';
if (numOfAsterisks > 1)
printAsterisks(numOfAsterisks-1);
}
Complete program by using above given recursive function:
//Header section
#include <iostream>
using namespace std;
//Function prototype
void printAsterisks(int n);
//main program
int main( )
{
//Call the method
printAsterisks(10);
return 0;
}
//Recursive function of printAsterisks:
//It takes one parameter which is a positive integer and
//that writes out that number of asterisks '*'.
//This astrisks display to the screen all
//on one line.
void printAsterisks(int numOfAsterisks)
{
cout << '*';
if (numOfAsterisks > 1)
printAsterisks(numOfAsterisks-1);
}
Output of program: