Question: #include using namespace std; void displayFibonacci ( int n ) { int a = 0 , b = 1 , next; for ( int i

#include
using namespace std;
void displayFibonacci(int n){
int a =0, b =1, next;
for (int i =1; i <= n; ++i){
cout << b <<"";
next = a + b;
a = b;
b = next;
}
cout << endl;
}
int factorial(int n){
if (n <=1) return 1;
return n * factorial(n -1);
}
int main(){
char choice;
do {
int option;
cout << "Menu:
";
cout <<"1. Display Fibonacci Series
";
cout <<"2. Compute Factorial
";
cout << "Enter your choice: ";
cin >> option;
if (option ==1){
int num;
cout << "Enter a Number: ";
cin >> num;
displayFibonacci(num);
} else if (option ==2){
int num;
cout << "Enter a Number: ";
cin >> num;
cout << "Factorial of "<< num <<" is "<< factorial(num)<< endl;
} else {
cout << "Invalid option. Please try again.
";
}
cout << "Return to Main Menu? [Y/N]: ";
cin >> choice;
} while (choice =='Y'|| choice =='y');
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!