Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This programming assignment will give you the opportunity to practice with all t

ID: 3571041 • Letter: T

Question

This programming assignment will give you the opportunity to practice with all the concepts that we have learned so far including functions and test your ability to solve the following problem: Design an algorithm to generate the first ten numbers in the Fibonacci sequence and store them in an array of size 10. Fibonacci sequence, FIBO(n), is defined as follows: FIBO(0) = 0, FIBO(1) = I, FIBO(n) = FIBO(n- l) + FIBO(n-2), for n = 0 for n = 1 for n > 1 For example, the first seven Fibonacci numbers are: 0, 1, 1, 2, 3, 5, and 8. You do not have to go too far in the sequence before encountering a number that exceeds MAXINT in value. Your program must generate the sequence FIBO(0), FIBO(2), FIBO(9). Use an iterative function or a recursive function in your program to calculate the nth Fibonacci number, FIBO(n), in the Fibonacci sequence and then store it in the array at position n. The program must prints out the values as follows: Sample Output: FIBO(0) = 0 FIBO(1)= I FIBO(2) = 1 FIBO(3) = 2 FIBO(4) = 3 FIBO(5) = 5 FIBO(6) = 8 FIBO(7) = 13 FIBO(8) = 21 FIBO(9) = 34

Explanation / Answer

// Program URL : http://ideone.com/lDNRaz

#include <iostream>

#define MAX_ARR 10 // Max array size 10 since the question is for 10 terms only

using namespace std;

// Fibonacci Recursive function

int FIBO(int FibIndex)
{
if(FibIndex < 2 )
return FibIndex;
else
return FIBO(FibIndex - 1) + FIBO(FibIndex - 2);
}

int main()
{
int Index = 0,arr[MAX_ARR];

// Loop for assigning the fibonacci nth series term output to array
for (Index=0;Index<MAX_ARR;Index++)
   arr[Index]=FIBO(Index);

// Loop for printing the array having fibonacci nth series term.

for (Index=0;Index<MAX_ARR;Index++)
   cout<<"FIBO("<<Index<<")="<<arr[Index]<<endl;
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote