Min & Max in Shell Script



clear

read -p "Enter array Size :" size
max=0

for((i=0;i<size;i++))
do
    read arr[$i]   
done

max=${arr[0]}
min=$max
for((i=0;i<size;i++))
do
    if((${arr[$i]}>$max));then
        max=${arr[$i]}
    fi
   
    if((${arr[$i]}<$min));then
        min=${arr[$i]}
    fi
done

echo "Array is :" ${arr[*]}
echo "Max Value is :" $max
echo "Min Value is :" $min






Min & Max in Shell Script Min & Max in Shell Script Reviewed by Unknown on 6:28 pm Rating: 5

No comments: