Saturday, 16 July 2016

Write a shell script in Linux/Unix to find the biggest number in an array.


echo "ENTER THE NUMBER OF ELEMENTS-"
read e
i=0
while test $i -le `expr $e - 1`
do
echo "ENTER $i ELEMENT-"
read a[i]
i=`expr $i + 1`
done
#SEARCHING THE BIGGEST
lar=${a[0]}
i=1
while test $i -le `expr $e - 1`
do
if test ${a[i]} -gt $lar
then
lar=${a[i]}
fi
i=`expr $i + 1`
done
echo "THE LARGEST NUMBER IS-" $lar


OUTPUT:

ENTER THE NUMBER OF ELEMENTS-
3
ENTER 0 ELEMENT-
6
ENTER 1 ELEMENT-
8
ENTER 2 ELEMENT-
12
THE LARGEST NUMBER IS-12









No comments:

Post a Comment

Popular Posts