Shell programming array biggest and smallest element


# Shell programming
# Read and display array.
# Find biggest and smallest in array

echo "Enter 5 values : "
for i in 0 1 2 3 4
do
read a[$i]
done

echo "Entered values are "
for (( i=0; i<5; i++))
do
echo -e "\t ${a[$i]}"
done

big=${a[0]}
small=${a[0]}

for ((i=1;i<5;i++))
do
if [ $big -lt ${a[i]} ]
then
     big=${a[$i]}
fi

if [ $small -gt ${a[$i]} ]
then
     small=${a[$i]}
fi
done

echo "Biggest is $big"
echo "Smallest is $small"

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu