Sunday, March 11, 2012

FIBONACCI SERIES ---- unix lab


FIBONACCI SERIES



AIM:
To write a Shell Program to print the Fibonacci series.

ALGORITHM:

Step 1: Start

Step 2: Read the Value of ‘n’

Step 3: Initialize i=2; a=0; b=1.

Step 4: Print the Value of ‘a’ and ‘b’

Step 5: When ‘i’ is lesser than ‘n’, solve the expression c=a+b

Step 6: Print c

Step 7: Swap the Values of ‘b’ to ‘a’ and ‘c’ to ‘b’

Step 8:  Solve the expression “i=i+1”

Step 9: Stop.


SHELL PROGRAM:

echo "Enter the Limit"
read n
i=2
echo "Fibonacci Series"
echo "----------------"
a=0
b=1
echo $a
echo $b
while [ $i -lt $n ]
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
i=`expr $i + 1`
done

SAMPLE OUTPUT:

Enter the Limit
8
Fibonacci Series
----------------
0
1
1
2
3
5
8
13























RESULT:
            Thus the Shell Program to print the Fibonacci Series was executed and the output was verified.

No comments:

Post a Comment