Answers for "prime number"

12

prime number

public class Prime {
    public static void main(String[] args) {

        int num = 29;
        boolean flag = false;
        for(int i = 2; i <= num/2; ++i){
            if(num % i == 0){
                flag = true;
                break;
            }
        }

        if (!flag)
            System.out.println(num + " is a prime number.");
        else
            System.out.println(num + " is not a prime number.");
}}
Posted by: Guest on May-25-2020
2

Prime Number

Numbers -- Prime Number
Write a method that can check if a number is prime or not
 
Solution:
public static boolean primeNumber(int num) {

    if(num <= 1){
        return false;
    }

    for(int i = 2; i < num; i++) {
        if(num % i == 0) {
            return false;
        }
    }

    return true;

}
Posted by: Guest on September-29-2021
5

prime number

def is_prime(n):
  if(n<0):
    print("n is not a nature number!")
    return False
  for i in range(1,ceil(n/2)+1):
    if (i != n and i != 1 and n%i == 0):
      return False
  return True
print(is_prime(int(input("number>>"))))
Posted by: Guest on July-10-2021
6

prime number

a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11)
suppose a number 'n' it can be divided by if '1' and only by itself then it can be a prime number
Posted by: Guest on January-19-2021
1

prime number

// PRIME NUMBER
// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.

let number = 5;
if(number < 2){
  console.log("less then 2 not prime")
}
let flag = false;
for(let i=2;i<number;i++){
  if(number % i === 0){
    flag = true;
  }
}
if(flag){
  console.log("Not prime ")
}
else{
  console.log("Prime")
}
Posted by: Guest on July-27-2021
0

prime number

#include<bits/stdc++.h>
using namespace std;
bool Is_Prime(long long x){
	if(x%2==0)return false;
	for(int i=3;i*i<=x;i+=2)
		if(x%i==0)return false;
	return true;
}
int main(){
	long long x;
	cin>>x;
	if(Is_Prime(x))cout<<"Is Prime";
	else cout<<"Is not Prime";
}
Posted by: Guest on April-30-2020

Browse Popular Code Answers by Language