CS133 Lab 4
Track 1
Write a program that inputs a number and determines whether the number is prime. After displaying the results, ask the user if they want to try again. At the end, print "Have a nice day!". Sample output:
Enter number: 25 The number 25 is not prime. Continue? (y/n) y Enter number: 17 The number 17 is prime. Continue? (y/n) n Have a nice day!
Track 2
The number π, or 3.1415..., can be calculated from the infinite series
π = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 ...
Query the user for the number of terms to use in the approximation, then calculate π. Then ask if they wish to repeat using a different number of terms. Indicate in your email the approximate number of iterations required to calculate π to six decimal places. Use double instead of float for extra precision.
Be sure your code follows the suggestions in the C Style Guide.
hint: This lab is easy to solve if you store the numerator and denominator in separate variables.