Question

using bash do the following script 1. Enter a list 2. Find the sum of the...

using bash do the following script
1. Enter a list
2. Find the sum of the list
3. Find the average of the list
4. Find the max of the list

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash
echo "How many number you want to enter : "
read no
echo
for i in `seq $no`
do
echo -n "Enter no $i : "
read num
nos[$i]=$num
done
echo "Entered Numbers are: ${nos[*]}"
echo
max=`printf '%s\n' "${nos[@]}" | awk '$1 > m || NR == 1 { m = $1 } END { print m }'`
echo "Max is: "$max

avg=`printf '%s\n' "${nos[@]}" | awk 'NR == 1 { s=0 } { s+=$1;} END { print s/NR}'`
echo "Average is: "$avg

sum1=`printf '%s\n' "${nos[@]}" | awk 'NR == 1 { s=0 } { s+=$1;} END { print s}'`
echo "Sum is: "$sum1

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
using bash do the following script 1. Enter a list 2. Find the sum of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT