# C++ Program For Calculate Percentage Of 5 Subjects

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

Logic :- First we will ask for total subject of student then we will enter marks of all those subject after that we will calculate a percentage of marks then we will print a student marks ,percentage and Grade of Student .Percentage formula are given Below.

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

For This Problem I Am Taking 5 Subject.

Solution :-

Method 1 :-

#include<iostream>
using namespace std;
int main()
{
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 :-

#include<iostream>
using namespace std;

int main()
{
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);
}

Output:-