👤

write a recursive function called print num pattern() to output the following number pattern. given a positive integer as input (ex: 12), subtract another positive integer (ex: 3) continually until a negative value is reached, and then continually add the second integer until the first integer is again reached. for this lab, do not end output with a newline. do not modify the given main program. ex. if the input is:

Answer :

The recursive function called print num pattern() to output the following number pattern is stated below:

What is recursion in a function?

A recursive function is a piece of code that executes by referencing itself. Simple or complex recursive functions are both possible. They enable more effective code authoring, such as the listing or compilation of collections of integers, strings, or other variables using a single repeated procedure.

Any function in the C programming language can call itself several times during the course of a program. Any function that repeatedly calls itself (directly or indirectly) without the program fulfilling a specific condition or subtask is referred to be a recursive function in this context.

The function in C++ is as follows:

int itr, kount;

void printNumPattern(int num1,int num2){

 if (num1 > 0 && itr == 0) {

 cout<<num1<<" ";

      kount++;

  printNumPattern(num1 - num2, num2);

   } else {

           itr = 1;

 if (kount >= 0) {

          cout<<num1<<" ";

          kount--;

          if (kount < 0) {

          exit(0);}

          printNumPattern(num1 + num2, num2);}}

}

To learn more about recursive, visit:

https://brainly.com/question/15085473

#SPJ4