Ask Question
29 March, 00:08

Write a recursive method called printNumPattern () to output the following number pattern. Given a positive integer as input (Ex: 12), subtract another positive integer (Ex: 3) continually until 0 or a negative value is reached, and then continually add the second integer until the first integer is again reached. Ex. If the input is:

+3
Answers (1)
  1. 29 March, 01:47
    0
    See Explanation Below

    Explanation:

    / / C+ + printNumPattern () recursive method

    / / Comments are used for explanatory purpose

    / / Only the recursive is submitted

    / / Method starts here

    void printPattern (int num1, int num2, bool dec)

    {

    / / Print num2.

    cout << num2 << " ";

    //Printing to num1

    if (dec = = false && num1 = =num2) {

    return; }

    / / Printing to 0 or negative.

    if (dec)

    {

    / / If num2 is greater than num2

    if (num2-num1 > 0)

    printPattern (num1, num2-num1, true);

    else / / recur with false dec

    printPattern (num1, num2-num1, false);

    }

    else / / If dec is false.

    printPattern (num1, num2+num1, false);

    }

    //End of recursive
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a recursive method called printNumPattern () to output the following number pattern. Given a positive integer as input (Ex: 12), ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers