Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Create a C program that performs the following tasks: Prompt the user for a number between 1 and 100 Verify the entered number is within

Create a C program that performs the following tasks:
Prompt the user for a number between 1 and 100
Verify the entered number is within the specified range
Note: Use the function, bool withinRange(int value, int min, int max).
If, and only if the entered number is within the specified range
Count the number of prime numbers that exist between 0 and the entered number
Use the function int countPrimes(int input) to count the primes numbers
Loop through all the numbers 0 to input (inclusively)
If a number is determined to be prime, increase the prime count by 1
Use the function bool isPrime(int testValue) to test if a number is prime or not
Perform the following tests to determine if a number is prime
If the number is less than 2, it is NOT prime (i.e., 0 and 1 are not prime)
If the number is even (except 2), it is NOT prime (i.e., 4, 6, 8, etc. are not prime)
If the number is evenly divisible by any odd number between 3 and less than the square root of the number, it is NOT prime (i.e., 27 is not prime)
Verify the results using the List of Valid Prime Numbers Between 0 and 1000
Display the input value and the prime count result (see Example Output section)
If the entered number is outside the specified range
Display an appropriate error message
Additional Notes
Use the sqrt function in the math.h header file to calculate the square root of the testValue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions