Monday, October 28, 2013

Largest of three numbers with the total and the average.

#WAP to find Largest of three numbers with the total and the average.

echo "Enter the 1st Number: "
read n1
echo "Enter the 2nd Number: "
read n2
echo "Enter the 3rd Number: "
read n3

total=`expr $n1 + $n2 + $n3`
avg=`expr $total / 3`
if [ $n1 -gt $n2 -a $n1 -gt $n3 ]
then
echo "$n1 is the Largest of three"
elif [ $n2 -gt $n1 -a $n2 -gt $n3 ]
then
echo "$n2 is the Largest of three"
elif [ $n3 -gt $n1 -a $n3 -gt $n2 ]
then
echo "$n3 is the Largest of three"
else
echo "All the three numbers are Equal"
fi
echo "Total: $total"
echo "Average: $avg"

No comments:

Post a Comment