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
Refer to the image on the right. Then, using the drop-down menu, identify the correct printer type. A: inexpensive home printer
Ivanshal [37]

Answer:

1st Option: Inkjet

2nd Option: Laser

Explanation:

Got it right on Edge 2020

6 0
3 years ago
You are late in the preparation of the computer graphics for your final report and presentation. You run into a friend who is gr
icang [17]

Answer:

Tactic Exchange

Explanation:

The approaching style of the student to his/her friend for help is of an influence categorized as the "Exchange Influence Tactic".

The Exchange Influence Tactic refers to when a person persuades someone or seeks influence over him/her by offering some sort of reward for their help rendered. It might also work by reminding other person of any favor which you offered in the past that should be repaid now.

Here the student is seeking help of his/her friend for completion of a final report for which he/she is already late. In exchange the student is assuring his/her friend the completion of certain spreadsheets which are pending on him/her. Hence, the student has used the exchange tactic to get his work done by offering a favor in response.

3 0
4 years ago
Biểu diễn cây sau bằng mảng một chiều
xeze [42]

Answer:

fhfhbrg

Explanation:

brikbgjgjkkjola

3 0
3 years ago
Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you
marishachu [46]

import random

num_rolls = 0

while True:

   r1 = random.randint(1, 6)

   r2 = random.randint(1, 6)

   print("Rolled: " + str(r1) + "," + str(r2))

   num_rolls += 1

   if r1 == r2 == 1:

       break

print("It took you "+str(num_rolls)+" rolls")

I added the working code. You don't appear to be adding to num_rolls at all. I wrote my code in python 3.8. I hope this helps.

4 0
3 years ago
If Johanna wants to label the x- and y-axes in Excel she should click Layout, then what?
denis-greek [22]
<span> If Johanna wants to label the x and y axes in an Excel chart, she should click anywhere on the chart, then click on the Layout tab. Under Labels, she should click on Axis Titles, and select the Secondary Horizontal Axis Title for x axis or <span>Secondary Vertical Axis Title for y axis. She should then select the text that is in the Axis Title box, and type the title name that she wants.</span></span>


6 0
3 years ago
Other questions:
  • What is the full path of the directory on this computer containing the SAM registry hive file
    15·1 answer
  • Anyone want to join my dîšćòrd
    8·2 answers
  • (70 points) This is a legit question that I have for a device FOR my homework.
    5·2 answers
  • What are the names of the 3 main languages used for making websites
    10·1 answer
  • What do level meters show?
    8·1 answer
  • What is the web of trust
    7·2 answers
  • A game developer is purchasing a computing device to develop a game and recognizes the game engine software will require a devic
    7·1 answer
  • Which tool allows users to share code and also serves as a social networking
    10·1 answer
  • Jonas is creating a presentation for students about volunteering. He wants to begin by speaking about the various opportunities
    11·1 answer
  • ________ are the symbolic codes used in assembly language?​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!