1. Write factorial function recusively 2. write fibonacci series code recusively
ID: 3859294 • Letter: 1
Question
1. Write factorial function recusively 2. write fibonacci series code recusively and show that it takes a long execution time when the number of n grows. 3. display values in a linked list in reverse order(use recusive technique)c++
#include <iostream>
using namespace std; 1. Write factorial function recusively 2. write fibonacci series code recusively and show that it takes a long execution time when the number of n grows. 3. display values in a linked list in reverse order(use recusive technique)
c++
#include <iostream>
using namespace std; 2. write fibonacci series code recusively and show that it takes a long execution time when the number of n grows. 3. display values in a linked list in reverse order(use recusive technique)
c++
#include <iostream>
using namespace std;
Explanation / Answer
Answer:
1.
#include<iostream>
using namespace std;
int inputfactorial(int input);
int main()
{
int input;
cout << "Enter a positive integer: ";
cin >> input;
cout << "Factorial of " << n << " = " << inputfactorial(input);
return 0;
}
int inputfactorial(int input)
{
if(input > 1)
return input * inputfactorial(input - 1);
else
return 1;
}
2.
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
ll recursionfibonacci(int input)
{
if (input == 1 || input == 2)
return 1;
else
return recursionfibonacci(input - 1) + recursionfibonacci(input - 2);
}
int main()
{
int input;
while (1)
{
cout<<"Enter any integer n to find nth fibonnaci number and 0 to exit ";
cin>>input;
if (input == 0)
break;
cout<<recursionfibonacci(input)<<endl;
}
return 0;
}
3.
void displayReverse()
{
display_recursive_reverse(start);
}
void display_recursive_reverse(input *read)
{
if(read) {
display_recursive_reverse(read->later);
cout << read->info << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.