#include
int smalldiv (int n)
{
int count;
count = 2;
while (count < n && n % count != 0)
{
count = count + 1;
}
return(count);
}
int main ()
{
int n;
cout << "Enter a natural number: ";
cin >> n;
if (n == smalldiv(n))
{
cout << n << " is a prime number" << endl;
}
else
{
cout << n << " is not a prime number" << endl;
}
return(0);
}
No comments:
Post a Comment