Question: Write a C++ program that lets the users enter positive integer numbers in a loop until the user enters a negative number. The program

 Write a C++ program that lets the users enter positive integer numbers in a loop until the user enters a 

Write a C++ program that lets the users enter positive integer numbers in a loop until the user enters a negative number. The program should check if the number entered is prime or not using a function. The function declaration is: bool isPrime (int n); where n is the integer to be checked. The function should return true if the number is a prime and false otherwise. A prime number is a number that is divisible by 1 and itself only. Examples of prime numbers are: 2, 3, 5,7, 11, 13, 17, 19, 23, 29, 31, etc. Sample Session: (Values in Green are entered by the user) Enter a positive integer (enter a negative integer to stop): 31 This is a prime number Enter a positive integer (enter a negative integer to stop): 16 This is not a prime number Enter a positive integer (enter a negative integer to stop): 22 This is not a prime number Enter a positive integer (enter a negative integer to stop): 43 This is a prime number Enter a positive integer (enter a negative integer to stop): -7667 Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a simple C program that fulfills the requirements includ... View full answer

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 Programming Questions!