0

Why is the answer 12?

int f=1, i=2; while(++i<5) { f*=i; } cout<<f; Can someone explain to me why the answer is 12? I thought that it would be 2 because you are basically multiplying f from i (1*2), as long as it is below 5.

5th Jan 2023, 1:10 AM
Gradi Maxime Kasita Mbatika
1 Answer
+ 3
You add 1 too i in the begining of the loop. So i Will be 3 and 4. Last loop Will be 3*4=12
5th Jan 2023, 2:04 AM
Andreas Lann
Andreas Lann - avatar