182k views
2 votes
The function below takes one parameter: an integer (begin). Complete the function so that it prints the numbers starting at begin down to 1, each on a separate line. There are two recommended approaches for this: (1) use a for loop over a range statement with a negative step value, or (2) use a while loop, printing and decrementing the value each time.

1 Answer

0 votes

Answer:

Program is in C++

Step-by-step explanation:

C++ Code

1) By using For Loop

void forLoopFunction(int value){

for(int start=value; start>0; start--){

cout<<start<<endl;

}

}

Explanation

Start for loop by assigning the loop variable to parameter value and condition will be that loop variable will be greater then 0 and at the end decrements the loop variable.

2) By usin WhileLoop

void whileLoopFunction(int value){

while(value>0){

cout<<value<<endl;

value--;

}

}

Explanation

In while loop first add the condition as variable must be greater then 0 and then print the value with endl sign to send the cursor to next line and at the end of the loop decrements the variable.

User Gsimoes
by
5.3k points