Explain me how can this thing happen? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0
8th Jul 2019, 1:03 PM
Anuj Raghu
Anuj Raghu - avatar
2 Answers
+ 1
It's because the loop only runs once. If you want it multiplied by 4 and 3, you should've made the loop like this: for (int i = 2; i > 0; i--)...
8th Jul 2019, 1:06 PM
Airree
Airree - avatar
0
i = 2 a[0] *= a[2] //a[0] = a[0] * a[2] = 1 * 4 = 4 i = 1 -> end loop because 1 is not > 1 Output: 4
8th Jul 2019, 1:33 PM
Denise Roßberg
Denise Roßberg - avatar