Skip to content

PHP Program 10

Write a program to compute, the Average and Grade of students marks.

<?php
$sub_1 = 95;
$sub_2 = 80;
$sub_3 = 84;
$sub_4 = 74;
$sub_5 = 73;

$total = NULL;
$average = NULL;
$grade = NULL;

$total = $sub_1 + $sub_2 + $sub_3 + $sub_4 + $sub_5;
$average = $total / 5.0;

if ($average >= 90)
    $grade = "A";
else if ($average >= 80 && $average < 90)
    $grade = "B";
else if ($average >= 70 && $average < 80)
    $grade = "C";
else if ($average >= 60 && $average < 70)
    $grade = "D";
else
    $grade = "E";

echo "The Total marks   = " . $total . "/500  <br>";
echo "The Average marks = " . $average . "  <br>";
echo "The Grade         = '" . $grade . "'  <br>";

?>

Output