Thursday, 21 April 2016

Random Number

#include<stdio.h>
#include<conio.h>
int a,x[20],M,c,i;
float r[20];
void main()
{
clrscr();

printf("\nEnter value of a:");
scanf("%d",&a);
printf("\nEnter value of Xo:");
scanf("%d",&x[0]);
printf("\nEnter value of c:");
scanf("%d",&c);
printf("\nEnter value of M:");
scanf("%d",&M);

printf("\nUsing LINEAR CONGRUENTIAL METHOD:\nThe random numbers generated are as follows:\n");
for(i=1;i<=10;i++)
{
x[i]=(a*x[i-1]+c)%M;
r[i]=(float)x[i]/M;
printf("\nX[%d] = %d\tr[%d] = %.2f",i,x[i],i,r[i]);
}

getch();

}

No comments:

Post a Comment