Write a C program to calculate the total marks of three subjects

Description: Take the marks of three subjects and print the total and the average.

Hint:

  • Total = sum of the three marks. Average = total / 3.

C program to calculate the total marks

#include <stdio.h>

int main(void) {
    int maths, science, english, total;

    printf("Enter marks of 3 subjects: ");
    scanf("%d %d %d", &maths, &science, &english);

    total = maths + science + english;
    printf("Total = %d\n", total);
    printf("Average = %.2f\n", total / 3.0);
    return 0;
}

Output:

Output of the above program is

Enter marks of 3 subjects: 78 85 91
Total = 254
Average = 84.67

How it works

  • The marks are added to get the total.
  • We divide by 3.0 to get a decimal average.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.