Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Study the following code,and then answer Questions 1 - 4. int sum = 0; const int

ID: 3688487 • Letter: S

Question

Study the following code,and then answer Questions 1 - 4.

int sum = 0;

const int MAX_ROWS = 5, MAX_COLS = 7;

int rows, columns;

for(rows = 0; rows < MAX_ROWS; rows++)

for(columns = 0; columns < MAX_COLS; columns++)

sum += rows + columns;

cout << "Value of sum is " << sum << endl;

1. How many times does the outer loop execute?

2. How many times does the inner loop execute?

3. What is the value of sum printed by cout ?

4. What would happen if you changed rows++ and columns++ to ++rows and ++columns ?

Explanation / Answer

1. The outer loop will execute 5 times.

2. the inner loop will execute 6 times

3. the value printed by cout is 175

4. There will be no change in the output