Q). Write the C++ Program for direct method of Mean
=> Prog :
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int n;
double sumF=0,sumFX=0;
cout<<"Enter the number input : ";
cin>>n;
double number[n];
double freq[n];
for(int i=0; i<n; i++){
cout<<"Number["<<i+1<<"] : ";
cin>>number[i];
cout<<"frequency["<<i+1<<"] : ";
cin>>freq[i];
}
cout<<"\n\n"<<setw(20)<<"Number"<<setw(10)<<"|"<<setw(20)<<"Frequency"<<endl<<endl;
for(int i=0; i<n; i++){
cout<<setw(20)<<number[i]<<setw(10)<<"|"<<setw(20)<<freq[i]<<endl;;
sumF=sumF+freq[i];
}
cout<<"\n**************** After Calculation ********************\n";
cout<<"\n\n"<<setw(20)<<"Number(x)"<<setw(10)<<"|"<<setw(20)<<"Frequency(f)"<<setw(10)<<"|"<<setw(30)<<"fx"<<endl<<endl;
for(int i=0; i<n; i++){
cout<<setw(20)<<number[i]<<setw(10)<<"|"<<setw(20)<<freq[i]<<setw(10)<<"|"<<setw(30)<<number[i]<<" x "<<freq[i]<<" = "<<number[i]*freq[i]<<endl;
sumFX=sumFX+number[i]*freq[i];
}
cout<<endl;
cout<<setw(30)<<"|"<<setw(20)<<"Summation F = "<<sumF<<setw(7)<<"|"<<setw(30)<<"fx = "<<sumFX<<endl;
double mean= sumFX/sumF;
cout<<"\n\n => MEAN : "<<mean<<endl;
}
Comments
Post a Comment