2048 problem recursion

when we are going to divide 2048/10 then it will print 204 (two hundred ) ??

Hi @advaitkr91
When you are making a recursive call to function and passing n/10 then first n/10 will be printed and after that n%10 will be printed. For example 2048/10 will first print two zero four and then eight will be printed.

can you help me with the flow of program. i have still a bit of confusion.

Let n be 2048
first rec(2048) is called then
rec(204) is called then
rec(20) is called then
rec(2) is called then
then rec(0) is passed and then the function returns then control returns back to rec(2) and prints two and returns then control comes back to rec(20) and then 20%10 is 0 so it prints zero and then returns and control comes back to rec(204) and 204%10 is 4 so it prints four and then returns and control comes back to rec(2048) and 2048%10 is 8 so it prints eight and returns to main function.

thanku Aayush , this will going to help me alot

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.