Question

In: Computer Science

Compute the 10,000th element of the pseudorandom sequence generated by the Middle-Square algorithm with seed=1003.

Compute the 10,000th element of the pseudorandom sequence generated by the Middle-Square algorithm with seed=1003.

Solutions

Expert Solution

#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;
}


Related Solutions

Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:
Chapter 3 Exercise 1Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:      1. Make a guess at the answer (you can pick n/2 as your initial guess).      2. Computer = n / guess.      3. Set guess = (guess +r) / 2.      4. Go back to step 2 until the last two guess values are within 1% of each other.Write a program that inputs an integer for n, iterates through the Babylonian algorithm until the guess...
Let G be a cyclic group generated by an element a. a) Prove that if an...
Let G be a cyclic group generated by an element a. a) Prove that if an = e for some n ∈ Z, then G is finite. b) Prove that if G is an infinite cyclic group then it contains no nontrivial finite subgroups. (Hint: use part (a))
Along, square, electrical heating element standing on a corner with one side of the square heating...
Along, square, electrical heating element standing on a corner with one side of the square heating element being 25mm, thermal conductivity k = 240 W/m ? K, density ñ = 2700 kg/m3, and specific heat cp = 900 J/kg ? K is installed in a duct for which air moves in cross flow over the heater at a temperature and velocity of 30°C and 10 m/s, respectively. (a) Neglecting radiation, estimate the steady-state surface temperature when, per unit length of...
2) Write an algorithm to compute the area of circles. Your algorithm should prompt the user...
2) Write an algorithm to compute the area of circles. Your algorithm should prompt the user to take the number of circles and their radius values. Then it should compute the areas of each circle. Finally, your algorithm will print both radius and area of all circles into the output. [N.B. you need to use iterative statement for solving the problem. Consider Pi = 3.14159] Input: Area of how many Circles you want to compute? 3 Key in radius values:...
Describe an efficient recursive algorithm for solving the element uniqueness problem
Describe an efficient recursive algorithm for solving the element uniqueness problem, which runs in time that is at most O(n2) in the worst case without using sorting.    
Which of the following is required for an insertion sequence element in E. coli to be...
Which of the following is required for an insertion sequence element in E. coli to be able to transpose? A gene for reverse transcriptase and long terminal repeats A gene for reverse transcriptase and inverted repeats A gene for transposase and inverted repeats A gene for transposase and long terminal repeats A gene for DNA polymerase and long terminal repeats Which type of deletions and/or insertion would not lead to frameshift mutations? A deletion that removes only a single amino...
Write a recursive algorithm replace (start) to replace the value of each element of A with...
Write a recursive algorithm replace (start) to replace the value of each element of A with that of the next element in A. A is a singly linked list.
Develop a recursive algorithm to find the smallest and largest element in an array and trace...
Develop a recursive algorithm to find the smallest and largest element in an array and trace the recursive function with appropriate message. using c++ add comment to the code
write a recursive algorithm to find the maximum element in an array of n elements and...
write a recursive algorithm to find the maximum element in an array of n elements and analyze its time efficiency. (I am using c++ programming language)
Use Recursive Algorithm to compute 5^23 Mod 8
Use Recursive Algorithm to compute 5^23 Mod 8
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT