Find the nth fibonacci number using iteration


Discuss the following:

Create a program "VC++.net" with the specified input and output.

Use a computational program or programs you have written to do the following exercises.

Given any non-negative integer n,

a. Find the nth Fibonacci number using iteration.

b. Find the nth Fibonacci number using recursion.

c.Compare the number of operations and the CPU time needed to compute Fibonacci numbers recursively vs. that needed to compute them iteratively.

Maybe these pseudocodes been helpful;

A Recursive Algorithm for Fibonacci Numbers.

Procedure fubonacci(n: nonnegative integer)
If n = 0 then Fibonacci(0) := 1
else if n = 1 then fiponacci(1) :=1
else fibonacci(n) := Fibonacci (n - 1) + fibnacci(n - 2)

An Iterative Algorithm for computing Fibonacci Numbers.

Procedure iterative Fibonacci (n : nonnegative integer )
If n=0 then y:=0
else
begin
x := 0
y := 1
For i := 1 to n - 1
begin
z := x + y
x := y
y := z
end
end

Solution Preview :

Prepared by a verified Expert
DOT NET Programming: Find the nth fibonacci number using iteration
Reference No:- TGS01937940

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)