Question: Recursion Show the stack frames (starting with mains frame) that are created while executing this program with the input 22. When a call returns, draw
Recursion
Show the stack frames (starting with mains frame) that are created while executing this program with the input 22. When a call returns, draw an arrow back to the frame it came from and write the return value on the arrow. Make an X over the frame when it is popped off the stack. // Convert a single-digit number to a single character with the same value. char digit2char( int n ) { return ( 0 + n%2 ); } // Precondition: n must be a positive number. string getBinary( int n) { if (n == 0) return "0"; if (n == 1) return "1"; int nextBit = n%2; return (getBinary( n/2 ) + digit2char( nextBit )) ; } int main (void) { int number; cout << "Please enter a positive number; I will convert it to binary. "; cin >> number; cout << getBinary( number ) <<" "; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
