Question

What is the output of the following pseudo-code?   ```     count = 0     for i from 1 to 3:         for j from 1 to i:             count = count + 1     print(count)     ```

A 3 Correct Answer Incorrect Answer
B 6 Correct Answer Incorrect Answer
C 9 Correct Answer Incorrect Answer
D 12 Correct Answer Incorrect Answer

Solution

Dry Run:            `count = 0`            `i = 1`:                `j = 1`: `count = 0 + 1 = 1`            `i = 2`:                `j = 1`: `count = 1 + 1 = 2`                `j = 2`: `count = 2 + 1 = 3`            `i = 3`:                `j = 1`: `count = 3 + 1 = 4`                `j = 2`: `count = 4 + 1 = 5`                `j = 3`: `count = 5 + 1 = 6`            Final `count = 6` 

Practice Next
ask-question