Commit 478105fe authored by Sarvesh's avatar Sarvesh

Upload new file

parent 02aa29ad
#!/usr/bin/bash
grep -oP '\S+' q4_in.txt > col.txt
sort -n col.txt > sorted.txt
i=0
sum=0
nums=$(<sorted.txt)
array[0]=0
for n in $nums; do
sum=$((sum+n))
i=$((i+1))
array[$i]=$n
done
echo "Mean=" $(echo "scale=3;($sum/$i)" | bc)
#echo ${array[*]} array
if [ $(($i % 2)) -ne 0 ]
then
middle=$[$((i/2))+1]
echo "Median=" ${array[$middle]}
else
ind1=$(($i/2))
ind2=$((ind1+1))
num1=${array[$ind1]}
num2=${array[$ind2]}
final=$((num1+num2))
echo "Median=" $(echo "scale=3;($final/2)" | bc)
fi
rm sorted.txt
rm col.txt
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