array , functions

T

tea-jay

hi again ..

well i do write the code but it doesnt work
i really dont what to do ?

this is my code

#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

void generate (int x[],int n);
void statistic (int x[],int n,double& m,double& d);
void result (double& m, double& d);

int main()
{
//declar the variables

int x[10];
double m,d;
int n=10;




//call functions

generate(x,n);
statistic(x,n,m,d);
result(m,d);


return 0;
}

// end of main

void generate (int x[],int n)// the function no.1

{


for(int i =1;i<10;i++) //using for loop
{

x= (rand()%(15-5+1))+5;
cout<<x; // cout the array
cout<<endl;
}

}

void statistics (int x[],int n,double & m,double & d)
{
int sum=0;
int i;
int z;


for(i=0;i<n;i++)

{
sum=sum+x;

}

m = 1.0*sum/n;

z=pow(x-m,2);

d=sqrt(z)/n;


}


void result (double& m,double& d) // the output of m&d
{
cout<<"The mean value is: "<< m <<endl;
cout<<"The standard deviation is :"<<d<<endl;

}
 
J

Jeroen

tea-jay schreef:
hi again ..

well i do write the code but it doesnt work
i really dont what to do ?

this is my code

#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

void generate (int x[],int n);
void statistic (int x[],int n,double& m,double& d);
void result (double& m, double& d);

int main()
{
//declar the variables

int x[10];
double m,d;
int n=10;




//call functions

generate(x,n);
statistic(x,n,m,d);
result(m,d);


return 0;
}

// end of main

void generate (int x[],int n)// the function no.1

{


for(int i =1;i<10;i++) //using for loop

for (int i = 0; ...
{

x= (rand()%(15-5+1))+5;
cout<<x; // cout the array
cout<<endl;
}

}

void statistics (int x[],int n,double & m,double & d)
{
int sum=0;
int i;
int z;


for(i=0;i<n;i++)

{
sum=sum+x;

}

m = 1.0*sum/n;

z=pow(x-m,2);

d=sqrt(z)/n;


}


void statistics (int x[],int n,double & m,double & d)
{
int sum = 0, sum2 = 0;

for(int i=0;i<n;i++)
}
sum += x;
sum2 += x*x;
}
m = sum/n;

// for std deviation: mean[(x-m)^2] = mean[x^2 - 2mx +m^2]
// = mean(x^2) - 2m mean[x] + m^2 //** mean[x] = m
// = mean(x^2) - m^2

d = sqrt(sum2/n - m*m);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top