We will write a program to get marks of five subject from the user and according to that
calculate the total marks obtained as well as the percentage.
C Program to Calculate Total Marks and Average
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,t;
float p;
clrscr();
printf("\n Enter marks of 5 subjects each out of 100 ");
printf("\n\n ********************************************");
printf("\n\n Maths = ");
scanf("%d",&s1);
printf("\n Science = ");
scanf("%d",&s2);
printf("\n English = ");
scanf("%d",&s3);
printf("\n History = ");
scanf("%d",&s4);
printf("\n Geography = ");
scanf("%d",&s5);
printf("\n ********************************************");
t=s1+s2+s3+s4+s5; //Total
printf("\n Total marks = %d/500",t);
p=t/5; //Percentage
printf("\n\n Percentage = %.2f",p);
printf("\n ********************************************");
getch();
}
Output:
C Program To Find Total Marks And Percentage Using Function
#include<stdio.h>
#include<conio.h>
int total();
int percentage();
int sum;
void main()
{
int t;
float p;
clrscr();
t=total();
printf("\n Total marks = %d/500",t);
p=percentage(); //Percentage
printf("\n\n Percentage = %.2f",p);
printf("\n ********************************************");
getch();
}
int total()
{
int s1,s2,s3,s4,s5;
printf("\n Enter marks of 5 subjects each out of 100 ");
printf("\n\n ********************************************");
printf("\n\n Maths = ");
scanf("%d",&s1);
printf("\n Science = ");
scanf("%d",&s2);
printf("\n English = ");
scanf("%d",&s3);
printf("\n History = ");
scanf("%d",&s4);
printf("\n Geography = ");
scanf("%d",&s5);
printf("\n ********************************************");
sum=s1+s2+s3+s4+s5; //Total
return(sum);
}
int percentage()
{
return(sum/5);
}
This way we can write a c program to calculate total marks and percentage.