Fibonacci sequence
Fabonacci sequece means it adds previous two numbers and generate the instant fabonacci number. Suppose we take number as f1=0 and f2=1
f1=0
f2=1
f3=f1+f2=0+1=1
f4=f3+f2=1+1=2
f5=f4+f3=2+1=3
f6=f5+f4=3+2=5
f7=f6+f5=5+3=8
f8=f7+f6=8+5=13 and so on.
Fibonacci sequence is represented as:
0 1 1 2 3 5 8 13 21 ......................
Algorithm:
Step 1: Assign fab=0,a=0,b=1,c=1.
Step 2: Get the number of terms upto which you want to generate the fibonacci number
Step 3: Print the value of fab to get fibonacci number series.
Step 4: Add a and b to get next fibonacci number.
Step 5: Assign the value of b to a.
Step 6. Assign the value of fab to b.
Step 7: Increment c with 1 and repeat step3,4,5,6 with the last value of c=n. (Here n is a number upto
which we want to print fibonacci sequence.)
Step 8: Stop.