Question
Develop an algorithm and a C program that asks the user to enter an integer greater than 1 and then lists all the prime numbers
Develop an algorithm and a C program that asks the user to enter an integer greater than 1 and then lists all the prime numbers between 1 and the user's input. Note: 1 is not a prime number. Remember: a prime number is evenly divisible by 1 and itself only. Note 1: the % operator might be very useful. Note 2: you can end a loop early by using the break statement (which is a keyword in C)... this may be useful.
Here are some additional requirements:
employ a programmer-created function (PCF) named greet( ) that will communicate the purpose of the program to the user
greet( ) shall be called from main( )
employ a programmer-created function (PCF) named get_input( ) that will obtain an integer from the user... get_input( ) will test the user's input to make sure the input is greater than 1... if the user's input is not greater than 1, get_input( ) will communicate an error message to the user and then ask the user to enter another integer
get_input( ) shall be called from main( )
get_input( ) shall employ a while loop as part of its error checking and asking the user to enter another integer
Note: do not try to determine if the user's input is an integer... only concern yourself with determining if the user's input is greater than 1
employ a programmer-created function (PCF) named list_primes( ) that will display all the prime numbers between 1 and the user's input (do not list 1 because it isn't a prime number)
list_primes( ) shall be called from main( )
list_primes( ) shall employ a while loop
DO NOT DO WEAK ALGORITHMS. EXAMPLE OF ALGORITHM CAN BE FOUND BELOW:
1. Ask the user to enter an integer great than 2
2. Record the user's input 3. Test the user's input to see if it is less than or equal to 2 3a. If true 3a1: Communicate to the user that the input must be greater than 2 3a2: Ask the user to enter another integer that is greater than 2 3a3: Record the user's input 3a4: Go to step 3 3b: If false 3b1: Go to step 4 4. Return the user's input to the function call
5. Terminate
All In C Programming
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