Ask Question

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

+5
Answers (1)
  1. 3 July, 09:58
    0
    void countUp (int num)

    {

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

    return;

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

    cout<
    }

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Modify the countUp () you wrote in the previous question to countUp (num), where num is a parameter. The function displays from 1 to num. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers