Please use unix or linux to write this, thank you 4) (20 marks) Write a C progra
ID: 3589844 • Letter: P
Question
Please use unix or linux to write this, thank you
4) (20 marks) Write a C program named a3q4.c which reads three columns of floating point numbers, prints them in alligned columns and calculates average of each of them. You must use double precision The program reads the standard input and produces the standard output Input The program will first read a positive integer number n which specifies how many rows of floating-point numbers follow. After that line, there will be n lines of floating point numbers with three numbers in each line separated by white space. An example of input file is: 4 1 -2 3.0 1.1 2.2 5.0 1.2 4 -12.4 0.3 1.3 4.4 OutputExplanation / Answer
Please find below shell script :
++++++++++++++++++++++++++++++++++
file="a.txt"
line=$(head -n 1 "$file")
flag=0;
column1=();
column2=();
column3=();
while IFS= read -r string
do
if [ "$flag" == "0" ]; then
flag=1;
continue;
fi
value1=`echo $string |cut -d' ' -f1`
value1=`printf '%.*f ' 2 $value1`
value2=`echo $string |cut -d' ' -f2`
value2=`printf '%.*f ' 2 $value2`
value3=`echo $string |cut -d' ' -f3`
value3=`printf '%.*f ' 2 $value3`
column1+=($value1)
column2+=($value2)
column3+=($value3)
printf "%10s" $value1
printf "%10s" $value2
printf "%10s" $value3
printf " "
done < "$file"
s=$(printf "%-30s" "-")
echo "${s// /-}"
tot1=0
for i in ${column1[@]}; do
tot1="$(echo $tot1 + $i | bc)"
done
tot2=0
for i in ${column2[@]}; do
tot2="$(echo $tot2 + $i | bc)"
done
tot3=0
for i in ${column3[@]}; do
tot3="$(echo $tot3 + $i | bc)"
done
printf "%10s" $tot1
printf "%10s" $tot2
printf "%10s" $tot3
printf " "