Question: Having issues creating a program to determine whether or not the number that the user inputs is prime or not prime. By the prime definition,

Having issues creating a program to determine whether or not the number that the user inputs is prime or not prime. By the prime definition, a natural number p is prime if and only if p is greater than 1 and the only natural numbers that divide p are 1 and p. Now I know, for it to be prime as well it can only be divisble by 2 natural numbers. How would I set the condition to where the divisibilty of the number that the user inputs is equal to 2 that way if its more than 2 it'll display that the number that the user entered is not prime.

#include #include

using namespace std;

int main() {

int p;

cout << endl << "Enter a positive integer: "; cin >> p;

if (p > 1 && (p/p || p/1)) { cout << "prime" << endl; } else { cout << "not prime" << endl; } return 0;

}

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!