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:

  1. Set divisor to 2

  2. Divide n by the divisor

  3. If the remainder is zero, go to step 7

  4. Increment the divisor

  5. If the divisor is <= , go to step 2

  6. The number is prime, algorithm complete, stop

  7. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!