Advertisements
Advertisements
Question
What is the output of the program code given below, when the value of x = 294?
int simple(int x)
{return (x<=0)? 0: x + simple(x/10);}Very Short Answer
Advertisements
Solution
325
Explanation:
The statement:
return ((x<=0)?0:x+simple(x/10)); performs itself recursively using x/10.
Hence the processing of x + simple(x/10) is calculated as 294 + 29 = 325.
shaalaa.com
Is there an error in this question or solution?
