Write a menu driven shell script which accepts a number N and an option to calculate the average of:
1. first ‘N’ odd numbers
2. first ‘N’ even numbers.
echo "Enter Size(N)"
read N
i=1
sum=0
echo "Enter Numbers"
while [ $i -le $N ]
do
read num #get number
sum=$((sum + num)) #sum+=num
i=$((i + 1))
done
avg=$(echo $sum / $N | bc -l)
echo $avg
Comments
Leave a comment