147k views
2 votes
Pls help quick

Question #4. This question is worth 55 points. You may use the exam reference sheet. Write the pseudocode for a procedure, pow2() that displays the nth power of 2 where n is a parameter passed into the procedure. PROCEDURE pow2 ) { }​

Pls help quick Question #4. This question is worth 55 points. You may use the exam-example-1

1 Answer

3 votes

Answer:

The procedure is completed as follows:

PROCEDURE pow2(n){

count = 1

power = 1

WHILE count <= n

power = power * 2

count = count + 1

END WHILE

Print power

}

Step-by-step explanation:

A pseudocode is not a real code and might not be syntactically correct. This is so because it only helps to understand what the code is all about and gives and insight of the code.

Having said that, the pseudocode for the program is as follows:

This line defines the procedure

PROCEDURE pow2(n){

This line initializes count to 1

count = 1

This line initializes power to 1

power = 1

The following iteration iterates from 1 to n

WHILE count <= n

This calculates the nth power of 2

power = power * 2

count = count + 1

The ends the while loop

END WHILE

This prints the calculated power

Print power

The procedure ends here

}

Note that: I'll assume that the 4 lines illustrated do not mean that the pseudocode be written in just 4 lines.

So, more lines would be needed

User Killogre
by
5.8k points