Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ program to find prime number using function

#include<iostream>
using namespace std;
bool isPrimrNumber(int number){
	bool isPrimeFlag=true;
	for(int i=2;i<number;i++){
	if(number%i==0){
		isPrimeFlag=false;
		break;
	}
}
		return isPrimeFlag;
}
int main()
{
	int number;
	cout<<"Please enter your number";
	cin>>number;
		bool isPrimeFlag=isPrimeNumber(number)
	if(isPrimeFlag)
	{
		cout<<"prime Number";
	}
	else
	{
		cout<<"not prime number";
	}
}
Comment

find primes in cpp

#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

#define N 1000000	//N is the Range (0..N)

bitset < N+1 > numbers;
vector < int > primes;

void sieve(){
    numbers.set();
    numbers[1] = 0;

    for (int i = 2; i < N; i++){
        if (numbers[i] == 1){
            cout<<i<<endl;
            primes.push_back(i);
            for (int j = i*i; j<=N; j+=i)
                numbers[j] = 0;
        }
    }
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ segmented sieve primes 
Cpp :: c++ typing animation 
Cpp :: less than operator overloading in c++ 
Cpp :: how to take space separated input in c++ 
Cpp :: how to store pair in min heap in c++ 
Cpp :: initialize 2d vector 
Cpp :: c++ get char of string 
Cpp :: all possible permutations of characters in c++ 
Cpp :: concatenate string program in c++ 
Cpp :: log base 10 c++ 
Cpp :: c++ vector move element to front 
Cpp :: input in c++ 
Cpp :: declaring 2d dynamic array c++ 
Cpp :: tolower funciton in cpp 
Cpp :: Count Prefix of a Given String solution leetcode 
Cpp :: sort vector in reverse order c++ 
Cpp :: std::iomanip c++ 
Cpp :: how to initialize a vector of pairs in c++ 
Cpp :: c++ rand include 
Cpp :: calculate factorial 
Cpp :: c++ insert into map 
Cpp :: length of string in c++ 
Cpp :: sort vector of strings 
Cpp :: c++ do every 1 minutes 
Cpp :: max two numbers c++ 
Cpp :: life the universe and everything solution c++ 
Cpp :: c++ lettura file 
Cpp :: SUMOFPROD2 solution 
Cpp :: c++ region 
Cpp :: find function in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =