Monday, 19 December 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<iostream>
using namespace std;
int main()
{
    /* Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
   int sub,marks,n,i,sum=0,tmp=0,arr[10],Percentage;

   cout<<"\nEnter number of subject : \n";
   cin>>n;
   
   tmp=n*100;
   
   cout<<"\nEnter The Marks: \n";
   for(i=0;i<n;i++)
   {
    cin>>arr[i];
   }
   for(i=0;i<n;i++)
   {
    sum=sum+arr[i];
   } 
   
   Percentage = ( sum * 100 ) / tmp;
   
   cout<<"\nPercentage Of Student : \n"<< Percentage<<endl;

   return (0);
}


Method 2:- This method is helpful when a number of subjects are fixed or less.

#include<iostream>
using namespace std;

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

   cout<<"\nEnter marks of 5 subjects : ";
   cin>>s1>>s2>>s3>>s4>>s5;

   sum = s1 + s2 + s3 + s4 + s5;
   
   per = (sum * 100) / total;
   cout<<"\nStudent Percentage Is : "<< per<<endl;

   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 30 Days of Code

2. Hacker Rank solution for Attribute Parser

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

4. Hacker Rank Solution For Conditional Statements

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. Geeksforgeeks Solution For " Sum of Middle Elements of two sorted arrays "

8. Java Program For Converting Temperature Celsius Into Fahrenheit

9. Geeksforgeeks Solution For " Two Repeated Elements "

10. Hacker Rank Solution For Virtual Functions



Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment