Horje
find prime number c++ Code Example
find prime number c++
#include <math.h>
// time: O(sqrt(n)) ..  space: O(1)
bool isPrime(int n) {
  if (n < 2) return false;
  int iter = 2;
  while(iter <= sqrt(n)) {
  	if (n % iter == 0) return false;
    iter++;
  }
  return true;
}
prime number c++
template<class T> bool isPrime(T n) 
{ 
	T i;
  	if(i<2) return false;
	for(i = 2; i * i <= n; i++) { 
    	if(n % i == 0)  return false; 
    } 
	return true; 
}




Cpp

Related
c++ replace Code Example c++ replace Code Example
c++ char array size Code Example c++ char array size Code Example
++ how to write quotation mark in  a string Code Example ++ how to write quotation mark in a string Code Example
what is a .cpp file Code Example what is a .cpp file Code Example
c++ iterate over vector of pointers Code Example c++ iterate over vector of pointers Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9