Question
I am not sure how to write the code for this assignment. These are the requirements: Write a program in C++ that asks the user
I am not sure how to write the code for this assignment. These are the requirements:
Write a program in C++ that asks the user to enter a natural number (non-negative integer) and then determines whether the number is a prime number or not. Then the program asks the user whether he/she wishes to enter another number and repeats the process.
Suggested steps are:
-
Set divisor to 2
-
Divide n by the divisor
-
If the remainder is zero, go to step 7
-
Increment the divisor
-
If the divisor is <= , go to step 2
-
The number is prime, algorithm complete, stop
-
The number is NOT prime, algorithm complete, stop
Program Specifications
Write a program to implement the trial division algorithm. You program must:
-
Ask the user to enter a number
-
Determine if the entered number is prime or not
-
Tell the user whether the entered number is prime or not
-
Ask the user whether he/she would like to enter another number to test
-
If the user responds in the affirmative (types a y or a Y, your program must be
-
able to handle both), start again
This is what the output should look like:
Enter an integer greater than 1 to check if it is a prime number: 3The number 3 is a prime number. Do you want to enter another number? (y or n): y Enter an integer greater than 1 to check if it is a prime number: 4The number 4 is NOT a prime number.
Do you want to enter another number? (y or n): nExiting program ...
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