SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size

How to know prime number in C++?

E-mail Print PDF
This article codes in Visual C++ shows you how to know one number is a prime number or is not.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Example: 2, 3, 5, 7,...
bool isPrime(int n)
{
	bool blnRe=true;
	
	for(int i=2;i<=n/2;i++)
	{
		if(n%i==0)
		{
			blnRe=false;
			break;
		}
	}

	return blnRe;
}
Download Source Code