Showing posts with label Fibonacci Series. Show all posts
Showing posts with label Fibonacci Series. Show all posts

Tuesday, March 24, 2015

Fibonacci Series

Algorithm
Step 1 : Start
Step 2 : Read number of terms as n
Step 3 : Initialize 0 to f1, 1 to f2 and 2 to i
Step 4 : Print initial fibonacci terms f1, f2
Step 5 : Generate next term using the formula f3 = f1 + f2
Step 6 : Print f3
Step 7 : Increment i by 1
Step 8 : Assign f2 to f1
Step 9 : Assign f3 to f2
Step 10 : Repeat steps 5–9 until i 􀁤 n
Step 11 : Stop

Program (fibo.sh)
# Fibonacci series using while loop
echo -n "Enter number of terms : "
read n
echo "Fibonacci Series"
f1=0
f2=1
echo -n "$f1 "
echo -n " $f2 "
i=2

Saturday, January 11, 2014

PROGRAM TO DETERMINE WHETHER THE GIVEN YEAR IS LEAP YEAR

echo enter a year
read n
if test `expr $n % 4` -eq 0
then
echo leap year
else
echo not a leap year
fi

~
~
OUTPUT

[staff@linuxserver staff]$ sh leap
enter a year
2008
leap year
[staff@linuxserver staff]$ sh leap
enter a year
2009
not a leap year



 PROGRAM TO GENERATE THE FINOCCI SERIES

echo "enter the number"
read n
echo "The result is"
c=0
a=0
b=1
echo "$a"
echo "$b"
n=`expr $n - 2`
while test $n -ne 0
do
c=`expr $a + $b`
echo "$c"
a=$b
b=$c
n=`expr $n - 1`
done
~



OUTPUT:


[eceb33@linuxserver eceb33]$ sh fiboo
enter the number
8
The result is
0
1
1
2
3
5
8
13