Average of marks of subjects using C++ programming language
Program:
#include<iostream>
using namespace std;
int main()
{
double n,sum=0;
double avg;
int j;
cout<<"enter number of subjects you have : ";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"enter marks for "<<i<<" subject : ";
cin>>j;
sum=sum+j;
}
cout<<"the sum of all subject marks is: "<<sum;
avg=sum/n;
cout<<"\nthe average of all subjects is : "<<avg;
return 0;
}
using namespace std;
int main()
{
double n,sum=0;
double avg;
int j;
cout<<"enter number of subjects you have : ";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"enter marks for "<<i<<" subject : ";
cin>>j;
sum=sum+j;
}
cout<<"the sum of all subject marks is: "<<sum;
avg=sum/n;
cout<<"\nthe average of all subjects is : "<<avg;
return 0;
}
output:
enter number of subjects you have : 5
enter marks for 1 subject : 45
enter marks for 2 subject : 44
enter marks for 3 subject : 43
enter marks for 4 subject : 43
enter marks for 5 subject : 34
the sum of all subject marks is: 209
the average of all subjects is : 41.8
Comments
Post a Comment