Program: Calculate Student Result

Explanation: This program accepts the marks of four subjects from the user, calculates the total and average marks, and then checks whether the student has passed or failed using the if-else statement.


#include <stdio.h>
#include <conio.h>

main()
{
    int a,b,c,d,total,avg;

    clrscr();

    printf("Enter Marks of Subject 1 : ");
    scanf("%d",&a);

    printf("Enter Marks of Subject 2 : ");
    scanf("%d",&b);

    printf("Enter Marks of Subject 3 : ");
    scanf("%d",&c);

    printf("Enter Marks of Subject 4 : ");
    scanf("%d",&d);

    total = a + b + c + d;
    avg = total / 4;

    printf("\nTotal Marks = %d",total);
    printf("\nAverage Marks = %d",avg);

    if(avg >= 35)
    {
        printf("\nStudent is Pass");
    }
    else
    {
        printf("\nStudent is Fail");
    }

    getch();
}

Output:

Enter Marks of Subject 1 : 70
Enter Marks of Subject 2 : 65
Enter Marks of Subject 3 : 80
Enter Marks of Subject 4 : 75

Total Marks = 290
Average Marks = 72
Student is Pass

Practice Exercises

Task 1: Write a C program to accept the marks of five subjects from the user, calculate the total and average marks, and display whether the student has passed or failed. A student is considered Pass if the average marks are 40 or above; otherwise, the student is Fail.

Goal: Learn how to calculate the total and average marks using arithmetic operators and use the if-else statement to determine the result.
💡 Hint: Use the formula Average = Total / 5 and check whether the average is greater than or equal to 40.
💡 Show Solution

#include <stdio.h>
#include <conio.h>

main()
{
    int m1,m2,m3,m4,m5,total,avg;

    clrscr();

    printf("Enter Marks of Subject 1 : ");
    scanf("%d",&m1);

    printf("Enter Marks of Subject 2 : ");
    scanf("%d",&m2);

    printf("Enter Marks of Subject 3 : ");
    scanf("%d",&m3);

    printf("Enter Marks of Subject 4 : ");
    scanf("%d",&m4);

    printf("Enter Marks of Subject 5 : ");
    scanf("%d",&m5);

    total = m1 + m2 + m3 + m4 + m5;
    avg = total / 5;

    printf("\nTotal Marks = %d",total);
    printf("\nAverage Marks = %d",avg);

    if(avg >= 40)
    {
        printf("\nStudent is Pass");
    }
    else
    {
        printf("\nStudent is Fail");
    }

    getch();
}

Output
Enter Marks of Subject 1 : 55
Enter Marks of Subject 2 : 68
Enter Marks of Subject 3 : 72
Enter Marks of Subject 4 : 49
Enter Marks of Subject 5 : 66

Total Marks = 310
Average Marks = 62
Student is Pass
Explanation: The program accepts the marks of five subjects, calculates the total and average marks, and uses the if-else statement to determine whether the student has passed or failed based on the average marks.