Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(Q1) Primality Testing 10 marks Recall that a number is a prime number if its only divisors are 1 and itself. Write a C program
(Q1) Primality Testing 10 marks 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 s 2vx. Precisely, the largest number y you test whether it divides x should be between vVx and 2Vx. The logic is that, if there exists a number z 2 Vx that divides x, then x-yz for some number y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started