Search
 
SCRIPT & CODE EXAMPLE
 

CPP

check prime number c++

bool prime(int a) { 
    if (a < 2)
        return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0)
            return false;
    }
    return true;
}
Comment

how to check if a number is prime c++

bool isPrime(int number){

    if(number < 2) return false;
    if(number == 2) return true;
    if(number % 2 == 0) return false;
    for(int i=3; (i*i)<=number; i+=2){
        if(number % i == 0 ) return false;
    }
    return true;

}
Comment

fast way to check if a number is prime C++

//O(sqrt(n))
bool isPrime(int num){
    if(num <= 1) return false;
    for(int i = 2; i <= sqrt(num); i++){
          if(num % i == 0) return false;
    }
    return true;
}
Comment

check prime cpp gfg

bool isPrime(int s){
   if(s <= 1) return false;
   if(s == 2) return true;
   for(int i = 2; i * i <= s; i++) {
       if(s % i== 0) return false;
   }
   return true;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ public class syntax 
Cpp :: how to code string to int converter c++ 
Cpp :: stringstream stream number to string 
Cpp :: how to reverse a vector 
Cpp :: Accpt array input in single line in cpp 
Cpp :: who to include a library c++ 
Cpp :: sqrt in c++ 
Cpp :: c++ function default argument 
Cpp :: c++ double is nan 
Cpp :: push local branch to another remote branch 
Cpp :: c++ pass array to a function 
Cpp :: See Compilation Time in c++ Program 
Cpp :: number of digits in int c++ 
Cpp :: length of string in c++ 
Cpp :: cpp func as const 
Cpp :: convert 2d array to 1d c++ 
Cpp :: c preprocessor operations 
Cpp :: Convert a hexadecimal number into decimal c++ 
Cpp :: c++ looping through a vector 
Cpp :: dynamic memory c++ 
Cpp :: all permutations with repetition C++ 
Cpp :: cpp define 
Cpp :: find substring in string c++ 
Cpp :: Youtube backlink generator tool 
Cpp :: char to int in c++ 
Cpp :: visual studio cpp compiler 
Cpp :: put text on oled 
Cpp :: clear previous terminal output c++ 
Cpp :: program to swap max and min in matrix 
Cpp :: what was the piep piper app 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =