What is the value of sum at the end of the following program:
#include #include using namespace std;
int main ()
{ int count = 10;
double sum = 0;
while (count > 8) {
sum = sum + pow(count, 2.0);
count--; }
cout << sum << endl; }

Respuesta :

Answer:

181

Explanation:

A while loop is a control flow statement that is continually executed until the boolean condition is false.

Considering the code:

First Iteration:

count = 10 (Initialized)

condition ( count > 8 is true)

sum = 0 (Initialized)

[tex] sum = 0 + (10)∧2 = 100 (Updated) [tex]

Second Iteration

count = 10 - 1 = 9

condition ( count > 8 is true)

[tex] sum = 100 + (9)∧2 = 100 + 81 = 181 (Updated) [tex]

Third Iteration

count = 9 - 1 = 8

condition ( count > 8 is false)

End of While Loop

Therefore, the number of times the loop was executed is 2 (Twice).

Final answered displayed is sum = 181.

ACCESS MORE