What is the output? int i, j, x = 0; for (i = 0; i < 5; ++i) for (j = 0; j < i; ++j) { x += (i + j − 1); break; } printf("%d", x);
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 6
Explanation
The inner loop runs only for j = 0 before breaking, adding i − 1 for i = 1 to 4: 0 + 1 + 2 + 3 = 6.
More Programming Languages and Computer Graphics questions
- Let A be the base class in C ++ and B be the derived class from A with protected inheritance. Which of the following statement is false for…
- A rectangle is bounded by x = 0, y = 0, x = 5 and y = 3. The segment joining (−1, 0) and (4, 5), clipped against this window, connects the…
- Which of the following algorithms is not used for line clipping?
- 1024 × 768 If we want to resize a pixels image to one that is 640 pixels wide with the same aspect ratio, what would be the height of the r…
- Java Virtual Machine (JVM) is used to execute architectural neutral byte code. Which of the following is needed by the JVM for execution of…
- Consider the following statements with respect to approaches to fill areas on raster systems : P: To determine the overlap intervals for sc…