Commit 02dce276 authored by Darshan Prabhu's avatar Darshan Prabhu

Update q4.sh

parent 0a66fad4
#!/usr/bin/bash
array=()
sum=0
count=0
while IFS= read -r line || [ -n "$line" ]
do
for word in $line
do
array[$count]=$word
sum=`expr $sum + $word`
count=$((count+1))
done
done <q4_in.txt
avg=`expr $sum / $count`
echo $avg
arr2=($(echo ${array[*]}| tr " " "\n" | sort -n))
i=`expr $count / 2`
if [ $(($count%2)) -eq 0 ]
then
a=${arr2[$i]}
b=${arr2[$(($i-1))]}
x=`expr $a + $b`
med=`expr $x / 2`
else
med=${arr2[$i]}
fi
echo $med
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment