0

Please, help me to explain why is output "24"

https://code.sololearn.com/WiRZVKqA7627/?ref=app

17th Sep 2020, 1:44 PM
Тимур Завьялов
Тимур Завьялов - avatar
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
17th Sep 2020, 1:53 PM
Abhay
Abhay - avatar
+ 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.
17th Sep 2020, 1:48 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Thank you)
17th Sep 2020, 2:06 PM
Тимур Завьялов
Тимур Завьялов - avatar