#include<stdio.h>
#include<conio.h>
void print(int x[],float r[],int n)
{
int i;
clrscr();
printf("\ni\tNumbers\t\tRandom Numbers\n\n");
for(i=0;i<n;i++)
printf("\n%d\t%d\t\t%f",i+1,x[i],(float)r[i]);
printf("\n\nThe total periods=%d",n);
getch();
exit(0);
}
void main()
{
int i,x[40],a,c,m,x0;
float r[40];
clrscr();
printf("\nEnter value for a=");
scanf("%d",&a);
printf("\nEnter value for c=");
scanf("%d",&c);
printf("\nEnter value for m=");
scanf("%d",&m);
printf("\nEnter value for x0=");
scanf("%d",&x0);
x[0]=x0;
r[0]=(float)x[0]/m;
for(i=1;i<40;i++)
{
x[i]=((x[i-1]*a)+c)%m;
r[i]=(float)x[i]/m;
if(x[0]==x[i])
print(x,r,i);
}
}
by Aanchal Gupta(MCA/4510/11)
by Aanchal Gupta(MCA/4510/11)
Comments