# C Program For Calculate Percentage Of 5 Subjects

Problem:- C Program For Calculate Total Marks Of 5 Subjects And percentage.means yo have to give a variable size of a subject like 2,3,5 and more subject as the user wants and you need to calculate the percentage of marks and also print the marks of each subject.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Logic:- First we will ask the user for the total number of the subject after that we will enter marks of all those subjects. Now we will calculate a percentage of marks and print student marks, percentage, and Grade of Student. Percentage formula is given Below.

Percentage of Marks = (all subject marks sum) / Total Subject *100 .

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

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

scanf("%d", &n);

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

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

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

}

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 subject * 100.

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

Enter number of subjects: 6 // 6 is user input
Enter The Marks: 78 65 56 89 45 90

Percentage of a student: 70.5

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

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

Solution:-

Method 1:- This method is helpful when a number of subjects are more than 6.

#include<stdio.h>

int main()
{
/* Program By Ghanendra Yadav
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 a number of subjects are fixed or less.

#include<stdio.h>

int main()
{
/* Program By Ghanendra Yadav
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);

}

Output:-

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.