Skip to content

Commit 328f13c

Browse files
author
Christian Bender
committed
fixed and improved Prime.c
1 parent b8cb524 commit 328f13c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

misc/Prime.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#include <stdio.h>
2+
#include <math.h>
23

34
int isPrime(int x) {
4-
if (x == 1)
5-
return 0;
6-
if (x % 2 == 0)
7-
return 0;
8-
for (int i = 3; i < x; i++) { // May replace x with sqrt(x)
5+
for (int i = 2; i < sqrt(x); i++) {
96
if (x%i == 0)
107
return 0;
118
}
129
return 1;
13-
10+
1411
}
1512

1613
int main() {

0 commit comments

Comments
 (0)