Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
A number is prime or not
#include<bits/stdc++.h> using namespace std; //whether a number is prime or not //Method-I /*bool isPrime(int N){ if(N == 1) return false; for(int i = 2; i <= N-1; i++){ if(N/i == 0) return false; } return true; }*/ //Method-II /*bool isPrime(int N){ if(N == 1) return false; for(int i = 2; i <= N/2; i++){ if(N/i == 0) return false; } return true; }*/ //Method-III bool isPrime(int N){ if(N == 1) return false; int L = sqrt(N); for(int i = 2; i <= L; i++){ if(N%i == 0) return false; } return true; } int main(){ int n; cin >> n; if(isPrime(n)){ cout << n << " is a Prime Number"; } else{ cout << n << " is not a Prime Number"; } return 0; }
run
|
edit
|
history
|
help
0
single_digit
Expected GCD
Calc
Hello World
2222aaaa
Maximum product subarray
4
ugly quick sort
Policy based smart pointer
BadCastAllExcept