.

Code Assignment WCrite A Simple C Program

1. C Code assignment Write a Simple C program, in C ( name it printPrime.c ) for printing out integer prime numbers in an infinite loop until the execution of your code is stopped by the user. Allow the user to stop by either typing Y or y to continue or X or x to exit. Each prime number should print one at a time.

2. Basic C programming question

Recall that a number is a prime number if its only divisors are 1 and itself. Write a C program that prints “Enter a number: ” to stdout and reads an unsigned integer from stdin. (Use scanf to do so. You do not need to perform any error checks.) Your program should print “x is a prime number.”, where x is the number you entered, if x is a prime number. Otherwise, it should print “x is not a prime number.” The exit code of your program should be 0.

For full marks, your program must meet the following requirements concerning the implementation:

 You should be able to handle any unsigned integer that fits in 64 bits.

  • When testing whether there exists a number y that divides x (and, thus, x is not a prime number), restrict yourself to integers y ≤ 2 p x. Precisely, the largest number y you test whether it divides x should be between p x and 2 p x. The logic is that, if there exists a number z ≥ p x that divides x, then x = yz for some number y ≤ p x and y also divides x. The reason why the permissible range of y is [2, 2p x] is explained in the next bullet.
  • For full marks, find the maximum value of y you test without calling the sqrt library function (which is a floating point function). Instead, use C’s bit shift operator to calculate the maximum value of y you need to test. This may return a number as large as 2p x. Implement your program in a file primetest.c
.