predict the output of following code.
int f = 1, i = 2
do {
f* = i
} while(++i < 5)
court<
(A) 12 (B) 5 (C) 4 (D) 24
Answers
Answered by
2
the final value of f will be 12
int f = 1, i = 2
do {
f* = i
} while(++i < 5)
in the first step i = 2
++i means i = i + 1
=> i = 2+1 = 3
since it is less than 5 so the loop executes, i.e
f* = i which is a short representation of
f = f * i
=> f = 1 * 3 = 3
again
i = i + 1
=> i = 3 + 1 = 4
since it is also less than 5 hence the loop executes again, i.e
f = f * i
=> f = 3 * 4 = 12
Now in the next increment,
i = 4+1 = 5
which is not less than 5 , so the loop will not execute any further
Hence the final value of f will be 12
Similar questions
English,
7 months ago
Business Studies,
7 months ago
Math,
7 months ago
Computer Science,
1 year ago
Science,
1 year ago
English,
1 year ago
Chemistry,
1 year ago