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.
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.
See Also: C++ Program For Calculate Percentage Of 5 Subjects
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()
{
/* Program By Ghanendra Yadav
Visit http://www.programmingwithbasics.com/
*/
int sub,marks,n,i,sum=0,tmp=0,arr[10],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()
{
/* 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);
}
Explanation Percentage in C
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
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
Find Percentage in C Output
Similar to Percentage in C
- Hacker Rank solution for Attribute Parser
- Hacker Rank solution for Vector-Sort
- Hacker Rank solution for Vector-Erase
- Java Program For Find The Gross Salary Of An Employee
- Hacker Rank solution for Sets-STL
- Hacker Rank solution for Maps-STL
- Hacker Rank solution for Print Pretty
- C++ Program For School Management System ( SMS Project ) With Source Code
- Hacker Rank solution for Virtual Functions
- C Program For Find A Grade Of Given Marks Using Switch Case
0 Comments: