What will the function call mystery(425) print? void mystery(unsigned int x) { if (x < 10) { cout << x; } else { mystery(x/10); cout << x % 10; } } Can you please explain why?
noone to help me on openstudy?
You need to think about what will happen within the if-statement. Is x less than ten? If so, what will happen? If not, what will happen instead? So 425 is not less than 10, so you need to look carefully to the else statement? What is happening there?
can you explain more my answer is contradicting
You pass the function 425, so when you enter the method your first evaluation asks if 425 is less than 10, it is not so it goes to the else, and passes 42.5 to your method and starts again.
how many times it prints the values?
Looks like 3 for the else statement and 1 for the if statement. First time through: x=425 second time: x=42.5 third time: x=4.25 So the third time it will print from the if statement and then return, at which point it will print from the else then return, where it will print from the else and return, where it again will print from the else.
thnks I got it.....so, the print value it is asking is the most current value...yes?
Depending on which print you are talking about. Inside the if statement you are only asking for the current value of x, assuming it is less than 10. In the else statement you are asking for the current value, of the remainder, of x mod 10.
@SUROj ... did u get answer or not?
yes i did thnks for asking
Join our real-time social learning platform and learn together with your friends!