HW#3, CSIT121 Computer Science-I Spring 2002 SUNY at Fredonia, Fredonia, New York Maximum Marks 10 Assigned: 11th April Due: 23rd April Q1. Write a program that accepts a number to be tested from the user. It then calls a function to determine if the given number is a prime number. Input Validation: Do not accept a negative number or a number more than 100. Hint (Sieve of Eratosthenes) Make a list of all the integers less than or equal to n (greater than one) and strike out the multiples of all primes less than or equal to the square root of n, then the numbers that are left are the primes. For example, to find all the odd primes less than or equal to 100 we first list the odd numbers from 3 to 100. The first number is 3 so it is the first odd prime-cross out all of its multiples. Now the first number left is 5, the second odd prime--cross out all of its multiples. Repeat with 7 and then since the first number left, 11, is larger than the square root of 100, all of the numbers left are primes 5 Marks Q2. Design a sorting utility program that reads exactly 12 integers from a file named "scores.dat" (it is provided online) and stores these numbers in an array. The program then calls a function and passes the array as a parameter. The function sorts the array in ascending order. The main program then calls another function. This function determines the mean and standard deviation of the 12 integers and displays the same on the screen followed by smallest and largest of the values. Standard deviation is obtained by squaring the difference between the mean and every number, adding all the results together and dividing by 12. Finally, the program opens the file “scores.dat” and stores all the integers, their mean, standard deviation, smallest and largest value found in a formatted way. 5 Marks