# C Program to Find Percentage of 5 Subjects || Percentage in C

Write a C Program to Find Percentage of 5 Subjects. First, we will ask the user for the total number of subjects after that we will enter the marks of all those subjects. Now we will calculate a percentage of marks and print student marks. This means you have to enter the subjects like 2,3,5. This totally depends on the user.

Percentage of Marks = (All Subject Marks Sum) / Total Subject *100.

``````printf("\nEnter number of subject : \n");

scanf("%d", &n);

for(i=0;i<n;i++)
{
scanf("%d", &arr[i]);
}

Now next step is to add or a sum of all subject marks entered by the user.

for(i=0;i<n;i++)
{
sum=sum+arr[i];

}``````

Tip:- always read the full post so you can understand better and check other solutions in different-different languages. Share and like if you like and I also respect suggestions if you want any modification in the post or if you have any better suggestions please let me know.

## C Program to Find Percentage of 5 Subjects

Method 1: This method is helpful when the number of subjects is more than 6. C Program for Percentage in C

``````#include<stdio.h>

int main()
{
Visit http://www.programmingwithbasics.com/
*/
int sub,marks,n,i,sum=0,tmp=0,arr,Percentage;

printf("\nEnter number of subject : \n");
scanf("%d", &n);

tmp=n*100;

printf("\nEnter The Marks: \n");
for(i=0;i<n;i++)
{
scanf("%d", &arr[i]);
}

for(i=0;i<n;i++)
{
sum=sum+arr[i];
}

Percentage = ( sum * 100 ) / tmp;

printf("\nPercentage Of Student : %d\n", Percentage);

return (0);

}``````

Method 2: This method is helpful when the number of subjects is fixed or less. The Second method for C Program to Find Percentage of 5 Subjects

``````#include<stdio.h>

int main()
{
Visit http://www.programmingwithbasics.com/
*/
int s1, s2, s3, s4, s5, sum, total = 500;
float per;

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

sum = s1 + s2 + s3 + s4 + s5;
printf("\nSum : %d", sum);

per = (sum * 100) / total;
printf("\nPercentage : %f", per);

return (0);

}``````

## Explanation Percentage in C

For this problem, I am taking 5 subjects. Now the first user enters a number of the subject of a student after that enters all subject marks and stores the marks in an array, see the below part of the code.

Now apply the formula and print the output calculated by the formula given.

Percentage = ( sum * 100 ) / tmp;

printf("\nPercentage Of Student : %d\n", Percentage);

here tmp is a number of subjects * 100.

#### Example of C Program to Find Percentage of 5 Subjects

Now take an example and check the output step by step. let's take 6 subjects in a semester and we have to calculate the percentage out of the total number 6 * 100 = 600.

Enter the Number of Subjects: 6 // 6 is the user input
Enter The Marks: 78 65 56 89 45 90

Percentage of a Student: 70.5

Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.