jeudi 26 mars 2015

A Program in which the user enters an integer, and the program indicates if that integer was a prime number or not


The question is:


"Create a program that asks the user to enter any integer, and then indicates to the user if the number entered was prime or not. Do this by creating a C++ function whose input is any integer; by counting the number of factors, your function should return true if the input is prime, and false otherwise."


Here's my code (please give direction not a precise answer):



using namespace std;

int i;

bool isPrime (int x)

{
if (x%i == 0)
{
return true;
}
else
{
return false;
}
}


int main()

{

for (int i = 2; i < x; i++)

{

}
}


Thanks!




Aucun commentaire:

Enregistrer un commentaire