Answer to Question #255989 in UNIX/Linux Programming for Kar

Question #255989
Write a script to print the marks of 5 subjects then calculator Sum and average. Hint (m1+m2+m3+m4+m5)/5
1
Expert's answer
2021-10-25T14:50:29-0400
# Write a script to print the marks of 5 subjects 
# then calculator Sum and average. Hint (m1+m2+m3+m4+m5)/5

if [[ "$#" -ne "5" ]]; then 
  echo "Usage: $0 mark1 mark2 mark3 mark4 mark5"
  exit 1
fi

sum=0
for x in $@; do
  sum=$(($sum+$x))
done

echo "Sum: $sum"
echo "Avg: " $(($sum/5))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS