I know the output of the program I just want help with the logic of figuring out the output a step by step processes of how to get to the output. thank you this is for my study guide please include step by step processes of how to reach output thank you. #include <iostream> using namespace std; int funcB(int); int funcA(int n) { if (n <= 1) return 1; else return n + funcB(n - 2); } int funcB(int n) { if (n <= 3) return 1; else return n * funcA(n - 3); } int main() { int num = 11; cout << funcA(num); return 0; }
Code Snippet
#include <iostream>
using namespace std;
int funcB(int);
int funcA(int n) {
if (n <= 1)
return 1;
else
return n + funcB(n - 2);
}
int funcB(int n) {
if (n <= 3)
return 1;
else
return n * funcA(n - 3);
}
int main() {
int num = 11;
cout << funcA(num);
return 0;
}
Output
101
Explanation
The code snippet uses the concepts of multiple recursions.
First Call - funcA(11) => 11 + funcB(9)
Second Call - funcB(8) => 11 + ( 9 * funcA(6) )
Third Call - funcA(6) => 11 + ( 9 * ( 6 + funcB(4) ) )
Fourth Call - funcB(4) => 11 + ( 9 * ( 6 + ( 4 * funcA(1) ) ) )
Final Call - funcA(1) => 11 + ( 9 * ( 6 + ( 4 * 1 ) ) ) [returns 1]
Solving the equation 11 + ( 9 * ( 6 + ( 4 * 1 ) )
)
We get 101.
QED
I know the output of the program I just want help with the logic of figuring...
B) draw the runtime stack fall the steps (a) write the output of the following program. The output must include everything that a computer may produce on its screen, including the prompts, input, output, and their positions. Suppose the input integers are 1 and 2, in this order. (b) Draw the run time stack for every step of execution on the next page. You need to mark the return address(es) yourself. #include <iostream> using namespace std; int a; int b;...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...
4. (10 pts) Show the output of the following program: (list the program outputs in the order as they would appear on screen) #include <iostream> using namespace std; int Mystery(int); int main() int x=2, y: y=Mystery(x - 1)+1; cout << "x="«x«", y="«y < endl; y=Mystery( 2 *x); cout << "x="«x«", y="«y < endl; return 0; int Mystery (int num) int y=5; // This is a regular local variable, not a static local variable int result; y=y+num; cout << "y=" <y<",...
Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...
Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }
Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...
Can I get a C++ code and output for this program using classes instead of using struct. The following program implements a Last In First Out (LIFO) stack. ( I want to use class for function definitions too and if main need.) #include <iostream> using namespace std; const int MAX = 100; struct stack { int s[MAX]; // an array of integers int top; // the index of the last number }; void push(stack &, int); void pop(stack&,...
bly language program that c l orresponds to the following Cr+ program.Include the memory addr Write a Pep/9 a include <iostream> using namespace std; int num; int main ( cout << "Enter a number:" cin >> num ; num = num * 4; cout << "num 4-<< num << endl; return 0 bly language program that c l orresponds to the following Cr+ program.Include the memory addr Write a Pep/9 a include using namespace std; int num; int main (...