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
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
Get step-by-step solutions from verified subject matter experts
