#include <iostream>
usingnamespace std;
int main()
{
long n;
cout << "enter a number : " << endl;
cin >> n;
if (n == 2 || n == 3 || n == 5 || n == 7)
{
cout << "The no is prime " << endl;
return 0;
}
if (n != 2 && n % 2 == 0 || n==1)
{
cout << "no is not a prime no " << endl;
return 0;
}
if (n % 3 == 0 || n % 4 == 0 || n % 5 == 0 || n % 6 == 0 || n % 7 == 0 || n % 8 == 0 || n % 9 == 0)
{
cout << "no is not a prime no " << endl;
return 0;
}
else
{
cout << "The no is prime " << endl;
return 0;
}
return 0;
}
If you actually did create a generic algorithm to figure out how to check for a prime number you would probably be a billionaire and inducted into the Computer Science Hall of Fame.. This is O(1) time, but won't work when you get to larger numbers.