fib

closed account (9Sh7ko23)
Write a program that neatly displays the first 21 numbers in the Fibonacci sequence in a table. Recall the definition for the Fibonacci sequence:

F0 = 0

F1 = 1

F2 = 1

Fn = Fn - 1 + Fn - 2



The program should calculate the numbers in the sequence using two different functions. In one display, use an iterative function and in the other use a recursive strategy. The driver code in main should do no calculations; instead, it should just draw the tables and populate them with well-formed calls to the two functions you write. Your functions should take a single integer argument and return the value of the appropriate term in the Fibonacci sequence using the argument as an index. For example Fibonacci(5) should return 5 because 5 is the fifth term in the Fibonacci sequence (it is really the 6th, but zero counts). Fibonacci(7) should return 13 because 13 is the 7th term in the Fibonacci sequence. Start your program with the following shell:
// INCLUDES AND NAMESPACES

#include <iostream>

#include <iomanip>

using namespace std;



// PROTOTYPES

int FibonacciIterative(int);

int FibonacciRecursive(int);



// MAIN

int main() {

int i = 0;



// YOUR DRIVER CODE GOES HERE



return 0;

}



// FUNCTION IMPLEMENTATIONS

// returns F_i of the Fibonacci sequence (iterative)

int FibonacciIterative(int i) {

// YOUR ITERATIVE IMPLEMENTATION GOES HERE

}



// returns F_i of the Fibonacci sequence (recursive)

int FibonacciRecursive(int i) {

// YOUR RECURSIVE IMPLEMENTATION GOES HERE

}

Last edited on
Well, you better get to it, then.
Write a program that neatly displays the first 21 numbers in the Fibonacci sequence in a table. Recall the definition for the Fibonacci sequence:


OK. I did. Now what?

It's really not that hard. Just use the things your teacher showed you in class.

We won't do your homework for you, but we will give you help when you are stuck. So, why don't you take a crack at it? When you get stuck, show us what you have and tell us what you are stuck on. We will be happy to help you then.
Topic archived. No new replies allowed.