Commit e645f14b authored by Keshav Agarwal's avatar Keshav Agarwal

week2 q4 and readme changes

parent bd7faddc
Members: Keshav - Q1
Aditya Aditya Mahesh - Q2
Keshav Agarwal Aditya - Q3
Mahesh Vishal - Q4
Vishal Mishra
\ No newline at end of file GIT: https://git.cse.iitb.ac.in/keshavagarwal/unagi/tree/master/week2
References:
https://www.tutorialspoint.com/unix/unix-special-variables.htm
https://stackoverflow.com/questions/1975849/how-to-split-a-line-into-words-separated-by-one-or-more-spaces-in-bash
\ No newline at end of file
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
sums=0 sums=0
counts=0 counts=0
arr=() arr=()
sort q4_in.txt > tem.txt xargs -n1 < q4_in.txt | sort -n > tem.txt
while read p while read p
do do
arr[counts]=$p arr[counts]=$p
counts=`expr $counts + 1` counts=`expr $counts + 1`
sums=`expr $sums + $p` sums=`expr $sums + $p`
done < tem.txt done < tem.txt
echo `expr $sums / $counts` echo `echo "$sums / $counts" | bc -l`
rem=$(( $counts % 2 )) rem=$(( $counts % 2 ))
if [ $rem -eq 0 ] if [ $rem -eq 0 ]
then then
echo "$(( ( arr[$(($counts/2))] + arr[$(($counts/2-1))] ) / 2 ))" mid=$((arr[$(($counts/2))] + arr[$(($counts/2-1))]))
echo `echo "$mid / 2" |bc -l`
else else
echo "${arr[$counts /2]}" echo "${arr[$counts /2]}"
fi fi
......
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