xxxxxxxxxx
def check_if_prime():
number = int(input("Enter number: "))
prime_lists = [1,2,3]
divisible_by = []
if number in prime_lists:
return divisible_by
if number==0:
return None
for i in range(2,number):
if number%i==0:
divisible_by.append(i)
return divisible_by
check_if_prime()
xxxxxxxxxx
#include "main.h"
int actual_prime(int n, int i);
/**
* is_prime_number - says if an integer is a prime number or not
* @n: number to evaluate
*
* Return: 1 if n is a prime number, 0 if not
*/
int is_prime_number(int n)
{
if (n <= 1)
return (0);
return (actual_prime(n, n - 1));
}
/**
* actual_prime - calculates if a number is prime recursively
* @n: number to evaluate
* @i: iterator
*
* Return: 1 if n is prime, 0 if not
*/
int actual_prime(int n, int i)
{
if (i == 1)
return (1);
if (n % i == 0 && i > 0)
return (0);
return (actual_prime(n, i - 1));
}
xxxxxxxxxx
def is_prime?(number)
# Prime numbers are greater than 1
return false if number <= 1
# Check for divisors from 2 to the square root of the number (to optimize the algorithm)
# If any divisor is found, the number is not prime
(2..Math.sqrt(number)).each do |divisor|
return false if number % divisor == 0
end
# If no divisors are found, the number is prime
return true
end
# Test cases
puts is_prime?(2) # Output: true
puts is_prime?(17) # Output: true
puts is_prime?(29) # Output: true
puts is_prime?(30) # Output: false
puts is_prime?(100) # Output: false
xxxxxxxxxx
def prime():
prime=True
while True:
for i in range(2,x-1):
y=x%i
if (y==0):
prime=False
break
if (x==0) or (x==1):
print(x , "is not a prime number")
elif (prime==True):
print(x , "is a prime number")
else:
print(x , "is not a prime number")
x=int(input("Enter a number:"))
prime()