+ 3

I have asked my questions in the form of comments in below code.

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

4th Mar 2022, 5:16 AM
King
King - avatar
5 odpowiedzi
+ 4
- Step number 1 : n=39 , i=2 ==> The method does not return a value . - Step number 2 : n=39 , i=3 ==> The method returns the value of 0 . - Step number 3 : n=23 , i=2--11 ==> The method does not return a value . - Step number 4 : n=23 , i=12<23/2 ==> Get out of the loop and The method returns the value of 1 .
4th Mar 2022, 6:38 AM
Tarik Khalil
Tarik Khalil - avatar
+ 3
This loop will never loop. The if statement in the loop has a return, which will break out of the loop. So in the first iteration it will go through the if statement and exits with 1 or 0. https://code.sololearn.com/cLJ0ezVG1l1a/?ref=app
4th Mar 2022, 5:55 AM
sneeze
sneeze - avatar
+ 3
In line 5 for the first iteration n=39 does the for loop ends bcs of 39%3=0(i=3)as return 0 is given. Answer : yes
4th Mar 2022, 6:10 AM
Tarik Khalil
Tarik Khalil - avatar
+ 3
Nicely done. Can you add some debugging lines to your code to see what's happening? Eg: cout << i; https://code.sololearn.com/cL7hvbePb5xw/?ref=app
4th Mar 2022, 6:11 AM
HungryTradie
HungryTradie - avatar
+ 2
- Step number 5 : n=49 , i=2--7 ==> The method returns the value of 0 . - Step number 6 : n=2, i=2<2/2 ==> Get out of the loop and The method returns the value of 1 FINISH
4th Mar 2022, 6:40 AM
Tarik Khalil
Tarik Khalil - avatar