Computer Science, asked by kulwinderrai0822, 1 year ago

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 shubhamjoshi033
18

The final value of f will be 12

The given program is as follows:

int f = 1, i = 2

do {

f* = i

} while(++i < 5)

Explanation :

in the first step i = 2 and f = 1

++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

Answered by kavyapurohit787
1

Answer:

The answer will be 12 ... don't forget to like...

Similar questions