Question: (1) The program segment below produces the following output. Explain the significance of the result. #include using namespace std; void main() { int sum =

(1) The program segment below produces the following output.

Explain the significance of the result.

#include

using namespace std;

void main() {

int sum = 0;

int amount = 0;

for( int j = 1; j <= 10; j += 1 ) {

sum += j;

amount += sum ;

}

cout << "sum = " << amount << endl;

}

(2) Given the following program segment, what value does the output statement display?

#include

using namespace std;

int value(int);

void main() {

cout << value(21) << endl;

}

int value(int x) {

return ( 4 + x * 3 / x + 3 ) ;

}

(3) Complete the code segment of a while() loop that executes its body five times as long as the loop counter variable is below a value of 3 .

int counter = 0;

while()

{

cout << counter << endl ;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!