fixed and improved Prime.c

This commit is contained in:
Christian Bender 2018-03-23 21:08:21 +01:00
parent b8cb5241a8
commit 328f13c1b2

View File

@ -1,16 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <math.h>
int isPrime(int x) { int isPrime(int x) {
if (x == 1) for (int i = 2; i < sqrt(x); i++) {
return 0;
if (x % 2 == 0)
return 0;
for (int i = 3; i < x; i++) { // May replace x with sqrt(x)
if (x%i == 0) if (x%i == 0)
return 0; return 0;
} }
return 1; return 1;
} }
int main() { int main() {