Q1) A simple random generator is obtained by the formula rnew = (a×rold+b)%m and then setting rold to rnew. Write a program that asks the user to enter an initial value for rold. (Such a value is often called a seed). Then print the first 100 random integers generated by this formula, using a = 32310901, b = 1729, and m = 224 .
Q2) How thick does paper folding get? Take one sheet out of your newspaper, and fold it in half, then fold it in half again, and again, and again. Can you fold it 30 times? Pretending that you can (you probably can’t fold it more than 8 times), how thick would it be after 30 times? Assume the paper is 1/200 cm. thick. Write a program to solve this puzzle. Prompt for the number of folds and output the thickness in meters.
Note : Run by pycharm
Q1)
Solution:
Screenshot of the code:
Sample Output:
Code To Copy:
//Include the header file.
import java.util.Scanner;
class Main {
//Define the main function.
public static void main(String[] args) {
//Create an object of Scanner type.
Scanner sc = new Scanner(System.in);
//Prompt the user to enter the value of r.
System.out.print("Enter the value for r_old: ");
int r_old = sc.nextInt();
//Prompt the user to enter the value of a.
System.out.print("Enter the value for a: ");
int a = sc.nextInt();
//Prompt the user to enter the value of b.
System.out.print("Enter the value for b: ");
int b = sc.nextInt();
//Prompt the user to enter the value of m.
System.out.print("Enter the value for m: ");
int m = sc.nextInt();
//Declare an array to store 100 randomly
//generated array.
int[] numberArray = new int [100];
//Begin the for loop.
for (int i = 0; i < numberArray.length; i++) {
//Compute the new value of r.
int r_new = (a * r_old + b) % m;
//Store it in the array.
numberArray [i] = r_new;
//Update the value of r_old.
r_old = r_new;
}
//Begin the for loop to diaplay the
//value of randomly generated values.
for(int i = 0; i < numberArray.length; i++){
System.out.println(numberArray[i]);
}
}
}
Q1) A simple random generator is obtained by the formula rnew = (a×rold+b)%m and then setting...
Take one sheet out of your newspaper, and fold it in half, then fold it in half again, and again, and again. Can you fold it 30 times? Pretending that you can (you probably can’t fold it more than 8 times), how thick would it be after 30 times? Assume the paper is 1/200 cm. thick. Write a program to solve this puzzle. Prompt for the number of folds and output the thickness in meters using python
(C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....