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

Which of the following did NOT contribute to the Great Depression? (A) buying stocks on margin (B) consumer installment buying (C) underconsumption of goods (D)
advantages and disadvantages of resonance
What are the differences between brinkmanship and containment?
What effect does temperature have on the characteristics of magma
advantages and disadvantages of resonance
wat are the names of flying mamoths
wat are the names of flying mamoths
I want a fairy tale, history or an autobiography written in Spanish and containing the present tense, past tense, past tense and future tense..I just need a sma
which value is a zero of the function defined by 6x^2+6x-36?
Syah work as senior designer in creative design company. he is an imaginative person and always updates himself with the latest technology and software. and he