Powered by Blogger.

Write a shell script to find the largest of three numbers and also find 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"
-------------------------------------------------------------------------------------------------
->OUTPUT:
---------

Enter the 1st Number:
5
Enter the 2nd Number:
6
Enter the 3rd Number:
7
7 is the Largest of three
Total: 18
Average: 6

Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment