Menu Close

Group Averages Method C++

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
int t[10],n,i,ts1=0,ts2=0;
float a,b,rs1=0,rs2=0,r[10],x1,y1,x2,y2;


cout<<"Enter the no. of observations"<<endl;
cin>>n;

cout<<"enter the different values of t"<<endl;

for(i=1;i<=n;i++)
{
cin>>t[i];
}

cout<<"\n enter the corresponding values of r"<<endl;

for(i=1;i<=n;i++)
{
cin>>r[i];
}

for(i=1;i<=(n/2);i++)
{
ts1 += t[i];
rs1 += r[i];
}

for(i=((n/2)+1);i<=n;i++)
{
ts2 += t[i];
rs2 += r[i];
}

x1=ts1/(n/2);
y1=rs1/(n/2);
x2=ts2/(n/2);
y2=rs2/(n/2);

b=(y2-y1)/(x2-x1);
a=y1-(b*x1);

cout<<"The value of a & b comes out to be "<<endl;
cout<<"a="<<setw(5)<<setprecision(3)<<a<<endl;
cout<<"b="<<setw(5)<<setprecision(3)<<b;

return 0;
}

Output

Enter the no. of observations
5
enter the different values of t
30 40 50 60 70
enter the corresponding values of r
1036.2 1056.3 1052.4 1049.3 1033.7
The value of a & b comes out to be
a= 714
b= 9.48

More Related Stuff