C Program to calculate the total marks and percentage of a student

In this section, you will learn how to read student’s details and calculate the total marks and percentage of a student.

We take student’s name, Roll no, class, section, marks in three subjects and then displayed a total marks and percentage obtained by a student.

Total = 1st subject marks + 2nd subject marks + 3rd subject marks

Average = Total/3

Percentage = (total/300) * 100

Program to calculate the total marks and percentage of a student

 

/* C Program: Read Student Roll_no, Name, Class, section and three subject marks and calculate total, percentage */ 

#include <stdio.h> 

int main() 
{
 long int rlno; 
 char name[25],
 clss[10],sec;
 short int m1,m2,m3;
 int total;
 float per;

 printf("\t\tEnter Student information \n"); 
 printf("Roll No : "); 
 scanf("%ld", &rlno);
 printf("Name of Student : ");
 fflush(stdin);
 gets(name);
 printf("Class : ");
 scanf("%s",clss); 
 printf("Section : ");
 fflush(stdin);
 scanf("%c",&sec);

 printf("Three Subject Marks :\n"); 
 scanf("%hd%hd%hd",&m1,&m2,&m3); 

 total = m1+m2+m3; 
 per = (total/300.0)*100;

 printf("------------------------------------------------\n"); 

 printf("Roll No : %ld\t\tName : %s \n",rlno,name); 
 printf("Class : %s\t\tSection : %c \n",clss,sec); 

 printf("------------------------------------------------\n");

 printf("Computer Organization : %d\n",m1);
 printf("C Programming : %d\n",m2);
 printf("Office Management Tools : %d\n",m3);

 printf("------------------------------------------------\n");

 printf("Total obtained Marks : %d\n",total);
 printf("Percentage : %.2f\n",per); 

 return 0;
}

 

Output :-

                     Enter Student information
Roll No : 31
Name of Student : CHRIS
Class : 10
Section : A
Three Subject Marks :
85 72 91
------------------------------------------------
Roll No : 31 Name : CHRIS
Class : 10 Section : A
------------------------------------------------
Computer Organization : 85
C Programming : 72
Office Management Tools : 91
------------------------------------------------
Total obtained Marks : 248
Percentage : 82.67
Related Articles

Leave a Reply