Monday, 7 March 2016

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. 

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

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.

See Also:- C++ Program For Calculate Percentage Of 5 Subjects

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[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 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);

}

See Also :- Java Program For Calculate Percentage Of 5 Subjects

Output:- 


C Program For Calculate Percentage Of 5 Subjects



C Program For Calculate Percentage Of 5 Subjects


You May Like This:-

1. Hacker Rank solution for Attribute Parser

2. Hacker Rank solution for Vector-Sort

3. Hacker Rank solution for Vector-Erase

4. Java Program For Find The Gross Salary Of An Employee

5. Hacker Rank solution for Sets-STL

6. Hacker Rank solution for Maps-STL

7. Hacker Rank solution for Print Pretty

8. C++ Program For School Management System ( SMS Project ) With Source Code

9. Hacker Rank solution for Virtual Functions

10. C Program For Find A Grade Of Given Marks Using Switch Case


No comments:
Write comments

Recommended Posts × +