0
Please, help me to explain why is output "24"
3 odpowiedzi
+ 5
when the loop runs first time i=2
,And then
res*=i
res=res*i=1*2=2
now the i value is incremented by 1
i is 3 now ,
When the loop runs second time
res=2*3=6
I value is incremented by 1 again which is 4 ,less than and equal to 4 ,so loop runs again and ,
res=6*4=24
After the i is incremented again it's value is 5 now which doesn't satisfies the condition (i.e. i<=n) ,so you exist out of loop and final value 24 is returned back to function
+ 3
In for loop i++ is same as ++i as far I know .So in your code the answer will be 1*2*3*4=24.
0
Thank you)