194k views
5 votes
Modify the countUp( ) you wrote in the previous question to countUp( num), where num is a parameter. The function displays from 1 to num.

1 Answer

2 votes

Answer:

void countUp(int num)

{

if(num==0) //base case.

return;

countUp(num-1);//Recursive call.

cout<<num<<" "; //printing the number.

}

for input num=25

Output:-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

Step-by-step explanation:

I have used recursion to print the numbers the function is in c++ language.In every recursive call we are decreasing num by 1.As the base case is reached.Then it will backtrack from 1 to num and then we are printing while backtracking.

User Ajimix
by
5.6k points