Header Ads

Shell Scripting : To determine the greatest of the 3 Number's - 03

The Shell Scripting Program to determine the Greatest of 3 Numbers.


Logic :  Using Conditional & Logical Operators such as 'If'.

Program Code:

#!/bin/bash
#To determine the greatest of the 3 Number's.

echo " Enter First Number [A] :"
read a
echo " Enter First Number [B] :"
read b
echo " Enter First Number [C] :"
read c

#Using conditional & Logical Operators
if [ $a -gt $b -a $a -gt $c ]
then
 echo " A is the Greatest"
elif [ $b -gt $a -a $b -gt $c ]
then   
 echo " B is Greatest"
elif [ $c -gt $a -a $c -gt $b ]
then
 echo " C is Greatest"
else
 echo " Invalid Input!"
fi

Program Output:

No comments