Runs Up and Runs Down

RANDOM NUMBER GENERATION
Test for Random Numbers
 Testing for Independence

Runs Up and Runs Down
Q) Write a program for implementation of Testing for Independence in Runs Up and Runs Down using C++ .
ANS.
/* Program for  Runs Up and Runs Down */
#include<iostream.h>
#include<math.h>
int main()
{
float N[10];
int n, count=0,1;
int c[10];
float mean , variance, variancesq, z0, za, z;
cout<<"n Enter Critical Value: ";
cin>>a;
cout<<"n Enter value of za/2: ";
cin>>za;
cout<<"n Enter number of nos. : ";
cin>>n;
cout<<"n Enter the nos.: ";
for(i=0;i<n;i++)
{
cin>>N[i];
}
for(i=0;i<n-1;i++)
{
if(N[i]<N[i+1])
{
cout<<"+";
c[i]=1;
}
else
{
cout<<"-";
c[i]=0;
}
}
for(i=0;i<n-1;i++)
{
if(c[i]!=c[i+1])
count++;
}
cout<<"n No of Runs="<<count<<"n";
mean=(2*n-1)/3;
variancesq=(16*n-29)/90;
variance=sqrt(variancesq);
z0=(a-mean)/variance;
if((za<z0)&&(z0<(0-za)))
cout<<"n The numbers are independent";
else
cout<<"n The numbers are auto-correlated and not independent";
return 0;
}


//OUTPUT:
Enter Critical Value: 0.05

Enter value of za/2: 1.96

Enter number of nos.10

Enter the nos.
0.15
0.27
0.37
0.10
0.50
0.60
0.80
0.70
0.59
-++-+++--
No of Runs=5

The numbers are auto-correlated and not independent