+ 6
How can I check a number if prime.
What will be the program in c which can help me to check a number if it is a prime number. And also it tell me that number which numbers divided returning Zero.
11 Réponses
+ 4
#In python
a = int(input())
factors = [i for i in range(1,a+1) if a%i == 0]
if len(factors)==2:
print(a,'is prime.')
else:
print(a,'is not prime.')
+ 9
Md Habibullah Solution : 💗 🙆♂️🤗
https://code.sololearn.com/clyWLOeD2Wmu/?ref=app
+ 5
Use the Erathnostenes algorithm.
Get input
For numbers from 2 to sqrt(num)+1 (for improving efficiency)
If the number is divisie by the number in the loop, return false
Else, return true.
+ 4
https://code.sololearn.com/c6yz0DMw8euz/#cpp
My implementation in C++. Hope this helps.
+ 2
Seive of Eratosthenes...
Google it.
+ 2
Sure...
Kishalaya Saha
+ 1
Dark Angel What you described doesn't sound like Eratosthenes' algorithm.
+ 1
Clementine💝 The Sieve of Eratosthenes is not that great for testing one number. And IMHO, for someone's first primality testing code, something simple would be better.
+ 1
for c there is no return typr like boolean so use 1 or 0 in place 1 for true and 0 for false nd use simple algorithm
0
a%2!=0
then a is prime number
except 2 ,2 is prime number though