Posts

Showing posts with the label Average

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; } 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

Program for average of 4 numbers in C++

 Program for average of 4 numbers in C++: #include<iostream> using namespace std; int main() { int a,b,c,d; double avg; cout<<"enter any four no"; cin>>a>>b>>c>>d; avg=(a+b+c+d)/4; cout<<"average is "<<avg; return 0; } output: enter any four no1 2 3 4 average is 2