1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mihalych1998 [28]
3 years ago
13

11.11 LAB: Number pattern Write a recursive function called PrintNumPattern() to output the following number pattern. Given a po

sitive 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. For this lab, do not end output with a newline. Ex. If the input is:
Computers and Technology
2 answers:
musickatia [10]3 years ago
6 0

Answer:

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);}}

}

Explanation:

We start by declaring global variables itr and kount

int itr, kount;

The function is defined here

void printNumPattern(int num1,int num2){

If num1 and itr are greater than 0 , then

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

Output num1, followed by a space

       cout<<num1<<" ";

Increment counter by 1

       kount++;

Call the recursion

       printNumPattern(num1 - num2, num2);

If otherwise

   } else {

Set itr to 1

       itr = 1;

If counter is 0 or positive

       if (kount >= 0) {

Output num1, followed by a space

           cout<<num1<<" ";

Decrease counter by 1

           kount--;

If counter is negative

           if (kount < 0) {

Exit function

               exit(0);}

Call the recursion

              printNumPattern(num1 + num2, num2);}}

}

Law Incorporation [45]3 years ago
4 0

Answer:

void PrintNumPattern(int start, int delta) {

cout << start << " ";

if (start > 0) {

 PrintNumPattern(start - delta, delta);

 cout << start << " ";

}

}

void main()  

{  

PrintNumPattern(12, 3);

}

Explanation:

Looking at the "palindrome" symmetry of the output, you want one nesting level of the function to print the output twice. Then you also don't need global variables.

You might be interested in
The Loanable Funds Market is built very similar to the Supply &amp; Demand Model. The Loanable Funds Market relates ____________
lawyer [7]
A should be the right answer
3 0
3 years ago
What can always be seen in the styles gallery??
tankabanditka [31]
<span>The quick styles gallery is the place where the available sets of fonts, designs, settings designed and stored in office applications. </span><span>The styles are all presented as examples in the gallery. </span><span> </span><span> </span><span>If a computer user wanted one of these styles, he can click one style and then it would automatically be applied to the document.  A style can be used, created and be removed if wanted.</span>
6 0
3 years ago
1. ___________ ensures the integrity and security of data that are passing over a network.
allochka39001 [22]

Answer:

The correct answer to the following question will be Option D (Network-security protocols).

Explanation:

  • Methods and procedures for protecting network data from unwanted information retrieval are managed by network security protocols.
  • They are a network-style protocol that guarantees the protection and privacy of data in transit through a wireless connection. It describes procedures and techniques for protecting network data from every unauthorized effort to access or remove data material.

Therefore, Option D is the right answer.

5 0
4 years ago
What are the two methods of creating a folder​
son4ous [18]

Answer:

1. right click empty space, go to New, and click New Folder

2. press Ctrl + Shift + N

Explanation:

5 0
2 years ago
What do want in future (computer enginner )<br>​
Debora [2.8K]
I wish to be a professor or maybe a singer/rapper and if they fail, then I wanna be a model

✨hope this helps✨

✨SammySilkWorm waz here✨

Here is my modeling shot

6 0
3 years ago
Read 2 more answers
Other questions:
  • Jane, an employee in the human resources department, has created several important PDF documents on her computer that all office
    9·2 answers
  • If you hear that an airplane crashes into the Empire State Building, and you immediately think of the 9/11 terrorist attack on t
    9·1 answer
  • (1) Prompt the user to enter a string of their choosing. Output the string.
    11·1 answer
  • Which of the following is the most appropriate unit to describe the rate at which data is transferred using the internet?
    6·2 answers
  • In computer science how can you define "copyright, designs and patents act 1988"?​
    8·1 answer
  • WHAT DO YOU LEARN IN CODE.ORG​
    11·1 answer
  • This is the number of items arranged in an order.
    7·2 answers
  • Differences between formula and function as used in spreadsheet​
    13·1 answer
  • 1. What is the difference between a group and a topic?
    10·1 answer
  • What are the two broad categories that individual definitional techniques fall under? Check all that apply. Demonstrative defini
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!