this program is much efficient for checking a single number for primality check.
bool check(int n){ if (n <= 3) { return n > 1; } if (n % 2 == 0 || n % 3 == 0) { return false; } int sq=sqrt(n); //include math.h or use i*i<n in for loop for (int i = 5; i<sq;i<=sq; i += 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; }