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
Complete the statement about WYSIWYG editors when you use a WYSIWYG editor you typically specify the continent and blank A.layou
erastovalidia [21]

Answer:

When you use a WYSIWYG editor you typically specify the content and layout while the editor generates the HTML code

Explanation:

Required

Complete the blanks

In WYSIWYG, the user of the application provides contents to the WYSIWYG software and also designs the appearance; The appearance is referred to as the layout.

Throughout the design, the user will not use HTML codes; it is the duty of the WYSIWYG editor to generate HTML code based on the input designs by the user.

6 0
3 years ago
A(n) _____ is a flexible tool used to analyze data using reports that do not have a predetermined format.
Mandarinka [93]

Answer:

decision support system

Explanation:

4 0
2 years ago
9.10: Reverse ArrayWrite a function that accepts an int array and the array ’s size as arguments . The function should create a
AleksandrR [38]

Answer:

#include <iostream>

using namespace std;

int * reverse(int a[],int n)//function to reverse the array.

{

   int i;

   for(i=0;i<n/2;i++)

   {

       int temp=a[i];

       a[i]=a[n-i-1];

       a[n-i-1]=temp;

   }

   return a;//return pointer to the array.

}

int main() {

   int array[50],* arr,N;//declaring three variables.

   cin>>N;//taking input of size..

   if(N>50||N<0)//if size greater than 50 or less than 0 then terminating the program..

   return 0;

   for(int i=0;i<N;i++)

   {

       cin>>array[i];//prompting array elements..

   }

   arr=reverse(array,N);//function call.

   for(int i=0;i<N;i++)

   cout<<arr[i]<<endl;//printing reversed array..

   cout<<endl;

return 0;

}

Output:-

5

4 5 6 7 8

8

7

6

5

4

Explanation:

I have created a function reverse which reverses the array and returns pointer to an array.I have also considered edge cases where the function terminates if the value of the N(size) is greater than 50 or less than 0.

8 0
3 years ago
Output a table that show the cube of the numbers 1-15<br> (C++)
Rainbow [258]

Answer:

The c++ program to display cube of numbers from 1 to 15 is given below.

#include <iostream>

using namespace std;

int main() {    

   // variables declared and initialized  

   int num = 15, k, cube;    

   cout << " Cubes of numbers from 1 to 15 are shown below " << endl;    

   for( k = 1; k <= num; k++ )

   {

       // cube is calculated for each value of k and displayed

       cube = k * k * k ;

       cout << " \t " << cube << endl;

   }

return 0;

}

 

OUTPUT

Cubes of numbers from 1 to 15 are shown below  

  1

  8

  27

  64

  125

  216

  343

  512

  729

  1000

  1331

  1728

  2197

  2744

  3375

Explanation:

The variables are declared and initialized for loop, cube and for condition in the loop – k, cube, num respectively.

Inside for loop which executes over k, beginning from 1 to 15, cube of each value of k is calculated and displayed. The loop executes 15 times. Hence, cube for numbers from 1 to 15 is displayed after it is calculated.

   for( k = 1; k <= num; k++ )

   {

      cube = k * k * k ;

       cout << " \t " << cube << endl;

   }

In the first execution of the loop, k is initialized to 1 and variable cube contains cube of 1. Hence, 1 is displayed on the screen.

In the second execution, k is incremented by 1 and holds the value 2. The variable cube contains cube of 2, which is calculated, and 8 gets displayed on the screen.

After each execution of the loop, value of k is incremented.

After 15 executions, value of k is incremented by 1 and k holds the value 16. This new value is greater than num. Hence, the loop terminates.

3 0
3 years ago
The function below tries to create a list of integers by reading them from a file. The file is expected to have a single integer
Setler [38]

Answer:

Check the explanation

Explanation:

def get_list_of_integers_from_file(filename):

int_list=[]

for line in open(filename).readlines():

try:

int_list.append(int(line))

except:

continue

return int_list

print(get_list_of_integers_from_file('file.txt'))

 

File.txt:

Kindly check the output below.

4 0
3 years ago
Other questions:
  • Orifice tubes are A. coded in American models only. B. coded by number for easy identification. C. similarly but not exactly siz
    12·1 answer
  • In 3-5 sentences, describe how you would insert a graph in your word-processing document.
    13·1 answer
  • A server, also called a(n) _______________, operating system is a multiuser operating system because it controls a central compu
    6·1 answer
  • A lookup field allows the user to select from a list of values when updating the contents of a field. true or false.
    11·1 answer
  • What layer in the Transmission Control Protocol/Internet Protocol (TCP/IP) model is responsible for defining a way to interpret
    11·1 answer
  • What are the two types of formulas in excel
    9·1 answer
  • Sometimes we care about the order of a list, and need to reorder the items according to a condition (alphabetical, numerical, et
    11·2 answers
  • Sabiendo que z1 = 10, z2 = 20, z3 =10 , z4 = 20, n1 = 1200 rpm.
    6·1 answer
  • How to call a variable as a tag in react native.
    12·1 answer
  • Structured query language (sql) enables data analysts to _____ the information in a database.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!