mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
fixed and improved Prime.c
This commit is contained in:
parent
b8cb5241a8
commit
328f13c1b2
@ -1,16 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int isPrime(int x) {
|
||||
if (x == 1)
|
||||
return 0;
|
||||
if (x % 2 == 0)
|
||||
return 0;
|
||||
for (int i = 3; i < x; i++) { // May replace x with sqrt(x)
|
||||
for (int i = 2; i < sqrt(x); i++) {
|
||||
if (x%i == 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
Loading…
Reference in New Issue
Block a user