Commit 15ad977a authored by Mohith Jagalmohanan's avatar Mohith Jagalmohanan

Adding Week1 Inlab

parents
#BASH
N=$1
sum=0
for ((i=1; i<=N; i++))
do
sum=$(($sum+$i*$i))
done
echo $sum
\ No newline at end of file
while read line; do
if [[ $line =~ .[5] ]]; then
echo "$line"
fi
done < q3_in.txt > q3_temp.txt
sort q3_temp.txt > q3_out.txt
rm q3_temp.txt
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
tr ' ' '\n' < q4_in.txt > temp.txt
sort temp.txt > temp2.txt
tr '\n' ' ' < temp2.txt > temp3.txt
while read -r x;
do
echo $x
done < temp3.txt
sum=0
y=0
for i in $x
do
sum=$(($sum+$i))
y=$(($y+1))
done
mean=$( echo "scale=2; $sum/$y" | bc)
echo $mean
####################################################
n=$y
rem=$(( $n % 2 ))
xx=($x)
if(($n%2==1))
then
echo ${xx[$n/2]}
fi
if(($n%2==0))
then
val1=${xx[$n/2]}
val2=${xx[$n/2 - 1]}
val=$(($val1+$val2))
median=$( echo "scale=2; $val/2" | bc)
echo $median
fi
rm temp.txt
rm temp2.txt
rm temp3.txt
\ No newline at end of file
Question No 1 done by Mohith Jagalmohanan (203050073)
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