+ 3
I have asked my questions in the form of comments in below code.
5 Réponses
+ 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 .
+ 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
+ 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
+ 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
+ 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