Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions