Header Ad

C Program to calculate sum of 5 subjects and find percentage

In this tutorial, we are going to write a C Program to calculate the sum of 5 subjects and find percentages in C Programming with practical program code and step-by-step full complete explanation.

C Program to calculate sum of 5 subjects and find percentage


C Program to calculate the sum of 5 subjects and find percentage.

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

void main()
{
	int s1,s2,s3,s4,s5,sum,total=500;
	float per;
	clrscr();

	printf("Enter marks of 5 subjects: ");
	scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

	sum=s1+s2+s3+s4+s5;

	printf("Sum = %d",sum);

	per=(sum*100)/total;

	printf("Percentage = %f",per);

	getch();
}


Output

Enter marks of 5 subjects: 65
65
50
60
60
Sum = 300
percentage = 60.000

Here in the above program we first include the header files and then in the main function, we declare the variables and use the clrscr() function to clear the output screen. after that, we use the sum variable to store the sum of all subjects and then print the value of the sum on the output screen.

After that, we find the percentage of the subjects using the sum variable and store it in the per variable, and then print it on the output screen.

Post a Comment

0 Comments