Wednesday 28 September 2011


GENERATING FIBONACCI SERIES

Aim:
To write a shell program to generate the Fibonacci series for the given limit.

Algorithm
1. Start the program.
2. Get the limit number n from the user.
3. Assigna=-1,b=lands=O.
4. Ifs<nthens=a+bandassigna=bandb=s.
5. Print the value of s.
6. Repeat step4.
7. Stop the program.

Program
#Fibonacci series
echo “Program to generate Fibonacci series”
echo “Enter the range to be displayed”
read n
a=0
b= 1
echo fibo series
echo $a
echo $b
i=2
while test $i -It $n
do
c = ‘expr $a + $b’
echo $c
i=expr$i+ 1’
a = $b
b = $c
done

Output :
        Program to generate Fibonacci series Enter the range to be displayed
5
0
1-
1
1
2
3

Result:
              Thus the Fibonacci series is generated.

0 comments:

Post a Comment