Sunday, March 11, 2012

GREATEST OF THREE NUMBERS unix lab


GREATEST OF THREE NUMBERS

AIM:
            To write a shell program to find the greatest of three Numbers.

ALGORITHM:

Step 1: Start
Step 2: Read the value of ‘a’, ‘b’ and ‘c’
Step 3: Check if ‘a’ is greater than ‘b’ and ‘a’ is greater than ‘c’
Step 4: Then print “A is Greater”
Step 5: If Step 3 is not satisfied check if ‘b’ is greater than ‘c’
Step 6: Then print “B is Greater”
Step 7: Else Print “C is greater”
Step 8: Stop.

SHELL PROGRAM:

echo "Enter Three Numbers"
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo "$a is Greater"
elif [ $b -gt $c ]
then
echo "$b is Greater"
else
echo "$c is Greater"
fi

SAMPLE OUTPUT:

Enter Three Numbers
12 14 16
16 is Greater

RESULT:
            Thus the program to find the greatest of three Numbers was executed and the output was verified.

No comments:

Post a Comment