So in my class we are studying recursive functions. But I just do not understand how they work.
I'll use this code as an example.
// n is written to the screen vertically
// with each digit on a separate line.
void write_vertical(int n) {
if (n < 10)
{
cout << n << endl;
}
else // n is two or more digits long
{
write_vertical(n/10);
cout << (n % 10) << endl;
}
}
So if int n = 123; it will print each digit on its own line.How does this happen? how does this function work step by step?