sharixiii7164 sharixiii7164
  • 20-08-2019
  • Computers and Technology
contestada

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

Respuesta :

ExieFansler ExieFansler
  • 27-08-2019

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

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.

Answer Link

Otras preguntas

Write a number from the list below inside a box. The number for each box should match the number below the box when rounded to the nearest hundredth 5.025 5.079
Why is man a special creature? What to words does he share in.
Is the question below a Fragment, run-on, or Correct? Although Mary has been my best friend.
How did the Virginia Plan address the issue of representation?
one main purpose of a colon is to?
South carolina eventually repealed its ordinance of nulification in exchange for
How can a number line help you find two integers that are the same distance from zero
What are some of the most important documents handed down from us from the past?
Which of the following is true of a eukaryotes cell in a multicellular organisms?
And outdoor deck is 7 feet wide. The perimeter of the deck is 64 feet. What is the length of the deck?