ShellProgramming
ShellProgramming
Aim:
To write a shell program to find greatest of three numbers.
Algorithm:
Step1: Declare the three variables.
Step2: Check if A is greater than B and C.
Step3: If so, then print A is greater.
Step4: Else check if B is greater than C.
Step5: If so print B is greater.
Step6: Else print C is greater.
Program:
echo "enter A"
read a
echo "enter B"
read b
echo "enter C"
read c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is greater"
elif [ $b -gt $a -a $b -gt $c ]
then
echo "B is greater"
else
echo "C is greater"
fi
RUN:
Sample I/P:
Enter A:50
Enter B:35
Enter C:55
Sample O/P:
C is greater
Result: Thus the shell program to find the maximum of three numbers is executed and
the output is verified successfully.
9
B) FIBONACCI SERIES:
Aim:
To write a shell program to generate Fibonacci series.
Algorithm :
Step 1 : Initialise a to 0 and b to 1.
Step 2 : Print the values of 'a' and 'b'.
Step 3 : Add the values of 'a' and 'b'. Store the added value in variable 'c'.
Step 4 : Print the value of 'c'.
Step 5 : Initialise 'a' to 'b' and 'b' to 'c'.
Step 6 : Repeat the steps 3,4,5 till the value of 'a' is less than given number.
Program :
echo “enter the number”
read n
a=0
b=1
i=0
while [ $i – le $n ]
do
c=`expr $a + $b`
echo $c
a=$b
b=$c
i=`expr $i + 1‟
done
Sample I/P :
Enter the no: 5
Sample O/P:
011235
Result :
Thus the shell program to find the fibonacci series is executed and output is verified
successfully.
10