C PROGRAMMING 1.Write a program which: Prints out all of the required informatio
ID: 672325 • Letter: C
Question
C PROGRAMMING
1.Write a program which: Prints out all of the required information for all assignments (see style sheet in D2L) )
2.Has a function randomInt that takes two integer arguments and returns a random integer in that range. This should be inclusive so if it is passed 1 and 17, both 1 and 17 could be returned.
3.Has a function randomDouble that takes two double arguments and returns a random double value in that range inclusively that has with 4 decimal places of randomness. This part is not clear. Should randomDouble return a double value with 4 digits or we want them to print out the random number with 4 digits (i.e; %.3lf)?? four significant digits. (Hint: multiply the range times a random number that has four significant digits (including leading zeroes) and then divide by a ten thousand).
4.Has a function nFiboinaocci that takes one argument “N” and returns the Nth Fiboinaocci term. Has a function isPrime that takes one argument and determines if that number is prime. If it is prime it returns “1” if it is not prime it returns “0”
5.Has a function nPrime that takes one argument “N” and returns the Nth prime number. As a reminder, the first prime number is 2.
6.Has a function nRandomSum that takes one argument “N” and returns the sum of the first N random integers that are even.
7.Has a function drawRandomSquares that takes three arguments, the width of the graphics window, the height of the graphics window, and the length of a square. It then fills the screen with filled squares of random colors. (Hint: Use two for loops nested together to generate the grid). Your program should prompt the user for the height and width of the screen. It should then prompt them for the size of the square in pixels. It should then prompt them for a number “N”.
8.Next, you should print out the Nth Fibinocci term. Then, you should print out the Nth prime number. Next, you should seed the random number generator with the number N and then print out the sum of the first N random integers that are even. It should then ask the user for a low and high Real number, and then print out N random Real numbers (doubles) in that range.
9.Finally, it should open a graphics window of size (width, height) and fill it with black. When the user clicks in the window, it should be filled with random colored squares. When the user clicks in the window again, the program should exit. Your main function should contain all of the scanf and printf statements in your program, and should also open and close the graphics window. You should do all of the other calculations and graphics calls in the appropriate functions. Where appropriate your functions can and should call your other functions to help them achieve their objective.
Explanation / Answer
2.
for (int i = 0; i < 10; i++)
{
double x = Math.random ();
System.out.println (x);
}
public static int[] randomArray (int n)
{
int[] a = new int[n];
for (int i = 0; i<a.length; i++)
{
a[i] = randomInt (0, 100);
}
return a;
}
The return type is int[], which means that this method returns an array of integers. To test this method, it is convenient to have a method that prints the contents of an array.
public static void printArray (int[] a) {
for (int i = 0; i<a.length; i++) {
System.out.println (a[i]);
}
}
3.
double randomDouble = (rand() % 1000) / 100.0;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.