0
What C or C++ program prints Fibonacci series?
What algorithm should I use to print out Fibonacci series in C++ or C?
1 Antwort
+ 1
Hi,
You can use following algorithm :
using iteration:
Procedure Fibonacci(n)
declare f0, f1, fib, loop
set f0 to 0
set f1 to 1
display f0, f1
for loop ← 1 to n
fib ← f0 + f1
f0 ← f1
f1 ← fib
display fib
end for
end procedure
using recursion:
START
Procedure Fibonacci(n)
declare f0, f1, fib, loop
set f0 to 0
set f1 to 1
display f0, f1
for loop ← 1 to n
fib ← f0 + f1
f0 ← f1
f1 ← fib
display fib
end for
END
Note:For c and C++ algorithm will be remain same but syntax will change as per language.