Middle-square method: Difference between revisions

Content deleted Content added
See also: cleaned up code.
Line 17:
 
 
#include<iostream.h>
 
void main()
 
{
 
int n=0,a,c,m,Z[100];
#include<iostream.h>
float U[100];
void main()
cout<<"enter z "<<endl;
int n=0,a,c,m, cin>>Z[1000];
cout<<"enter a "<<endl;
float U[100];
cin>>a;
cout<<"enter z "<<endl;
cout<<"enter c "<<endl;
cin>>Z[0];
cin>>c;
cout<<"enter a "<<endl;
cout<<"enter m "<<endl;
cin>>a;
cin>>m;
cout<<"enter c "<<endl;
cout<<"n"<<"\t"<<"Zn"<<"\t"<<"Un"<<"\t"<<endl;
cin>>c;
cout<<"enter m ..."<<"\t"<<"..."<<"\t"<<"..."<<"\t"<<endl;
do {
cin>>m;
Z[n+1]=((Z[n]*a)+c)%m;
cout<<"n"<<"\t"<<"Zn"<<"\t"<<"Un"<<"\t"<<endl;
if(Z[n+1]!=0)
cout<<"..."<<"\t"<<"..."<<"\t"<<"..."<<"\t"<<endl;
U[n+1]=(float)1/(Z[n+1]);
do
else
{
Z[n+1]=((Z[n]*a)+c)%m0;
if(Z[n+1]!=0)
cout<<"..."n<<"\t"<<"..."Z[n+1]<<"\t"<<"..."U[n+1]<<"\t"<<endl;
U[n+1]=(float)1/(Z[n+1]);
n++;
else
} while(Z[n+1]!=Z[0]);
 
}
cout<<n<<"\t"<<Z[n+1]<<"\t"<<U[n+1]<<"\t"<<endl;
n++;
while(Z[n]!=Z[0]);
 
}