A shell-script to calculate total and average of n user entered number.

echo -e “Enter the total number:\c”

read n

a=$n

while [ $n -gt 0 ]

do

echo -e “Enter the number:\c”

read n1

sum=expr $sum + $n1

n=expr $n - 1

done

echo Total of number from 1 to $a :$sum

avg=expr $sum / $a

echo Average is:$avg

 

Output::

 

Enter the total number:5

Enter the number:2

Enter the number:3

Enter the number:5

Enter the number:4

Enter the number:1

Total of number from 1 to 5 :15

Average is:3

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.