echo -n "Enter the Number of Subjects = "
read numSub
declare -a subMarks
for (( i=0; i<$numSub; i++ ))
do
echo -n "Enter the Marks(Out of 100) in Subject $(($i+1)) = "
read subMarks[$i];
done
for (( i=0; i<$numSub; i++ ))
do
sum=$(($sum + ${subMarks[$i]}))
done
totalMarks=$(($numSub * 100))
percentage="`expr \( $sum \* 100 \) / $totalMarks`"
echo "Marks Obtained $sum / $totalMarks"
echo "Percentage Obtained = $percentage %"
if [ $percentage -ge 80 ]
then
grade="A"
elif [[ ($percentage -ge 60) && ($percentage -lt 80) ]]
then
grade="B"
else
grade="C"
fi
echo "Grade Obtained = $grade"
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./studentGrades.sh
#Enter the Number of Subjects = 3
#Enter the Marks(Out of 100) in Subject 1 = 90
#Enter the Marks(Out of 100) in Subject 2 = 80
#Enter the Marks(Out of 100) in Subject 3 = 85
#Marks Obtained 255 / 300
#Percentage Obtained = 85 %
#Grade Obtained = A
#root@slack-linunx:~/scripts#
read numSub
declare -a subMarks
for (( i=0; i<$numSub; i++ ))
do
echo -n "Enter the Marks(Out of 100) in Subject $(($i+1)) = "
read subMarks[$i];
done
for (( i=0; i<$numSub; i++ ))
do
sum=$(($sum + ${subMarks[$i]}))
done
totalMarks=$(($numSub * 100))
percentage="`expr \( $sum \* 100 \) / $totalMarks`"
echo "Marks Obtained $sum / $totalMarks"
echo "Percentage Obtained = $percentage %"
if [ $percentage -ge 80 ]
then
grade="A"
elif [[ ($percentage -ge 60) && ($percentage -lt 80) ]]
then
grade="B"
else
grade="C"
fi
echo "Grade Obtained = $grade"
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./studentGrades.sh
#Enter the Number of Subjects = 3
#Enter the Marks(Out of 100) in Subject 1 = 90
#Enter the Marks(Out of 100) in Subject 2 = 80
#Enter the Marks(Out of 100) in Subject 3 = 85
#Marks Obtained 255 / 300
#Percentage Obtained = 85 %
#Grade Obtained = A
#root@slack-linunx:~/scripts#
0 comments:
Post a Comment