Created
July 16, 2015 03:51
-
-
Save oieioi/aa8aef8f7f6c11e8ff69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define FALSE 0 | |
#define TRUE 1 | |
int isPrime(int num) { | |
if (num == 0) { | |
return FALSE; | |
} | |
if (num == 1) { | |
return FALSE; | |
} | |
if (num == 2) { | |
return TRUE; | |
} | |
int i; | |
for (i = 3; i < num - 1; i += 2) { | |
//printf("loop %i in %i ", num, i); | |
if (num % i == 0) { | |
return FALSE; | |
} | |
} | |
return TRUE; | |
} | |
int main(void){ | |
int targets[100] = {0}; | |
int i; | |
for (i = 0; i < 100; i++) { | |
char temp[10]; | |
fgets(temp, 10, stdin); | |
int result = atoi(temp); | |
if (result == 0) { | |
break; | |
} | |
targets[i] = result; | |
} | |
int checkCount; | |
for (checkCount = 0; checkCount < 100; checkCount++) { | |
if (targets[checkCount] == 0) | |
break; | |
int result = 0; | |
if (targets[checkCount] > 2) | |
result++; | |
int i; | |
for(i = 3; i < targets[checkCount]; i += 2){ | |
int prime = isPrime(i); | |
if (prime == TRUE) { | |
//printf("%i,", i); | |
result++; | |
} | |
} | |
printf("%i\n", result); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment