Dremendo Tag Line

Calculate total marks and percentage in C

scanf() - Question 18

In this question, we will see how to input marks obtained in 5 different subjects in C programming using the scanf() function and find out the total marks and percentage obtained. To know more about scanf() function click on the scanf() function lesson.

Q18) Write a program in C to input marks obtained in 5 different subjects and find out the total marks and percentage obtained by the student. Assume that the maximum mark in each subject is 100.

Program

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

int main()
{
    int e,m,h,g,c,total;
    float per;
    printf("English ");
    scanf("%d",&e);
    printf("Maths ");
    scanf("%d",&m);
    printf("History ");
    scanf("%d",&h);
    printf("Geography ");
    scanf("%d",&g);
    printf("Computer ");
    scanf("%d",&c);
    total=e+m+h+g+c;
    per=(total/500.0)*100;
    printf("Total Marks=%d\n",total);
    printf("Percentage=%.2f",per);
    return 0;
}

Output

English 75
Maths 62
History 84
Geography 77
Computer 91
Total Marks=389
Percentage=77.80
video-poster