Coronavirus made it tough but we keep working remotely with no delays. Get 15% OFF your First Order
Get 15% OFF your First Order

Programming

Briefly explained below.

I’m trying to learn for my Computer Science class and I’m stuck. Can you help?

write a pseudocodes for the two c++ program’s below and execute them in a LaTeX overleaf.

1) fibonacci_Iterative_

#include <iostream>
using namespace std;

int fib(int maxFib){

long curr, currMinus2 = 1, currMinus1 = 1;
cout << “nfib 1 = ” << currMinus2 << endl;
cout << “fib 2 = ” << currMinus1 << endl;

for (int i = 3; i <= maxFib; i++){
curr = currMinus2 + currMinus1;
cout << “fib ” << i << ” = ” << curr << endl;
currMinus2 = currMinus1;
currMinus1 = curr;
}
return curr;
}
int main()
{
int myElement = 0;
long myResult;

while (myElement < 3){
cout << “nPlease enter an integer greater than 2: “;
cin >> myElement;
}

myResult = fib(myElement);

cout << “nnResult = ” << myResult << endl;
return 0;
}

2) fibonacci_recursive_

// Recursive solution for calculating the fibonacci series
// From HackerRank video

#include <iostream>
using namespace std;

long fib(long n) {
if (n <= 0) {
return 0;
}
else if (n==1) {
return 1;
}
else {
return fib(n-1) + fib(n-2);
}
}

int main()
{
long fibResult = fib(15); // Higher than 45 will be an exponentially long wait
cout << “nResult = ” << fibResult << endl;
return 0;
}

Looking for this or a Similar Assignment? Click below to Place your Order

× How can I help you?