In: Computer Science
Compute the 10,000th element of the pseudorandom sequence generated by the Middle-Square algorithm with seed=1003.
#include<stdio.h>
int main()
{
long int seed = 1023;
int i, n;
long int next;
printf("How many number you want to generate : ");
//User will input n = 10000 because we want the 10000th
number
scanf("%d", &n);
printf("Random Numbers are : ");
for(i = 0; i < n; i++)
{
seed = seed * seed; //1003*1003 = 1046529 i.e. squaring the seed
value
seed = seed / 100; //Take the dividend 1046529/100 = 10465
seed = seed % 10000; // Take the reminder 10465 % 10000 =
0465
//We have extracted the middle four digits from the square of
1023
//Now seed contains the value 0060
next = seed;
//Storing the vaule of seed in next
printf("%d\n ", next);
}
printf("\n");
return 0;
}