Added more efficiencies

This commit is contained in:
lunarised 2019-04-30 11:29:25 +12:00
parent 1055c69c42
commit 563f1d2bf6

View File

@ -1,21 +1,27 @@
#include <time.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int is_prime(int n){ int is_prime(int n){
int i; int i;
for(i=2;i<n;i++){ for(i=3; i<((n/2)+1);i++){
if(n%i == 0){ if(n%i == 0){
return 0; return 0;
} }
i++;
} }
return 1; return 1;
} }
int main(void){ int main(void){
clock_t se, ss;
int n = 2; int n = 2;
for (n = 2; n < 100; n++){ ss = clock();
for (n = 2; n < 100000; n++){
if(is_prime(n)){ if(is_prime(n)){
printf("%d\n", n); printf("%d\n", n);
} }
} }
se = clock();
printf("Operation Time: %f\n", (se - ss)/(double)CLOCKS_PER_SEC);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }