Need need help with my C lab. The randomx.h is used in the program. I have a sep
ID: 3847682 • Letter: N
Question
Need need help with my C lab. The randomx.h is used in the program. I have a seprate file linking the randomx.h, I just need help with the code part.
Explanation / Answer
I am not sure about linking the randomx.h.As far as the code is concerned, this should do it.
#include<iostream>
#include<randomx.h>
#include<math.h>
using namespace std;
int main()
{
int n;
cout<<"Enter number of values needed: ";
cin>>n;
double values[n];
double sum=0;
double sumsq=0;
double Dmean,Ddev;
cout<<" Enter desired mean and desired standard deviation ";
cin>>Dmean>>Ddev;
for(int i=0;i<n;i++)
{
values[i]=rx_normal(Dmean,Ddev);//generates n numbers from rx_normal and stores in array values
sum=sum+values[i];//adds the values of value[]
sumsq=sumsq+(values[i]*values[i]);//adds the squares of values in value[]
}
double real_mean=sum/n;//real mean
double sq=sumsq/n;
double real_stddev=sqrt(sq-(real_mean*real_mean));//real standard deviation
double diff_mean=abs(real_mean-Dmean);
double diff_sdev=abs(real_stddev-Ddev);
cout<<" Difference in the desired mean and real mean: "<<diff_mean;
cout<<" Difference in the desired standard deviation and the real standard deviation: "<<diff_sdev;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.