In this article, we will learn the C++ program to calculate average and percentage. Users enter the total number of subjects and their marks. The program displays its average and percentage.
Program: Calculate the average and percentage of student grade
//C++ program to calculate average and percentage
#include<iostream>
using namespace std;
int main()
{
int mark[20], i, number;
float sum=0, pct, avg;
cout<<"Enter total number of subjects: ";
cin>>number;
for(i=0; i<number; i++)
{
cout<<"\nEnter mark for subject "<<i+1<<": ";
cin>>mark[i];
sum=sum+mark[i];
}
avg=sum/number;
pct=(sum/(100*number))*100;
cout<<"\nAverage Marks of all "<<number<<" Subjects: "<<avg<<"\n";
cout<<"Percentage in all "<<number<<" Subjects: "<<pct<<"%\n";
return 0;
}