I'm having difficulties in understanding the logic regarding the recursion? Can someone help me explain how do I get an output of 7 in it?
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
using namespace std;
int recursion_sample(int x) {
return (x)? x%10 + recursion_sample(x/10): 0;
}
int main()
{
cout << recursion_sample(2500);
return 0;
}
|
Last edited on
Last edited on