0

Why this answer is correct?

I got that question in C++ chalange and I have no idea why the correct answer is 0. I thought that the answer is 17.5 but no. What is the output of this code? int function (double x) { if (x > 0) { function (x - 2.5); }else { return x; } } int Main () { cout << function (20.0); Answer: 0 Sorry for bad gramma :)

18th Mar 2019, 1:02 PM
gewyckler
gewyckler - avatar
2 Respostas
+ 3
The function calls itself> Check the following code and I think that you will understand.. https://code.sololearn.com/cEFndo1hoops/#cpp
18th Mar 2019, 1:29 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Well that was helpful, thanks you very much. I didn't know that the function will go over and over until march the if condition.
19th Mar 2019, 6:42 AM
gewyckler
gewyckler - avatar