Loading…
OS · Decisions · Program 20 · In the record
Write the shell script to print the grade after input the marks of four different subjects
1#!/bin/bash2 3echo "Enter the marks of 4 subjects (out of 100):"4read m1 m2 m3 m45 6total=$((m1 + m2 + m3 + m4))7percent=$((total / 4))8 9if (( percent >= 90 ))10then11 grade="A+"12elif (( percent >= 80 ))13then14 grade="A"15elif (( percent >= 70 ))16then17 grade="B"18elif (( percent >= 60 ))19then20 grade="C"21elif (( percent >= 50 ))22then23 grade="D"24else25 grade="F"26fi27 28echo "Total = $total / 400"29echo "Percentage = $percent%"30echo "Grade = $grade"85 90 78 92Enter the marks of 4 subjects (out of 100): 85 90 78 92 Total = 345 / 400 Percentage = 86% Grade = A
Run program 20 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.