To print the Fibonacci series for 1 to n
value
Description
A fibonacci series is defined as follows The first term
in the sequence is 0
The second term in
the sequence is 1
The
sub sequent terms 1 found by adding the preceding two terms
in the sequence Formula: let t1,t2,…………tn be
terms in fibinacci sequence
t1=0,t2=1tn=tn-2+tn-1……where n>2
algorithm:
Step 1: start
Step 2: initialize
the a=0, b=1 Step 3: read n
Step 4: if n== 1
print a go to step 7. else goto step 5
Step 5: if n== 2 print a, b go to
step 7
else print a,b
Step 6: initialize i=3
i)
if
i<= n do as follows. If not goto step 7 c=a+b
print c
a=b
b=c
increment
I value
goto step 6(i)
Step 7: stopflow chart for To print the Fibonacci series for 1 to n value
No comments:
Post a Comment