226k views
3 votes
Wha is the output of the following code fragment?

for (int i = 0; i < 15; i++{
if (i %4 ==1)
(i + " " )'
}
A) 1 3 4 7 9 11 13
B) 1 5 9 13
C) 1 5 9 13 16
D) 1 4 8 12
E) 1 3 5 7 9 11 13 15

User Gambit
by
7.3k points

1 Answer

5 votes

The output of the corrected code fragment would be '1 5 9 13', which are the numbers less than 15 that have a remainder of 1 when divided by 4.

The code fragment is intended to iterate over integers from 0 up to, but not including, 15. Within the loop, there is a conditional check that tests whether the current iteration variable i has a remainder of 1 when divided by 4. If it does, the value of i followed by a space is supposed to be output. There is, however, a syntax error in the given code fragment which prevents it from compiling and running.

Assuming the typos are fixed and the intended output is to print values, the code would print numbers that, when divided by 4, have a remainder of 1. Therefore, the values are 1, 5, 9, and 13.

User Balu Sangem
by
7.9k points