[CODE]/*
* Prime Number
*
* Date : 2005. 11. 7
* Made by chobocho@kroea.com
* Synopsis : 1 - 1,000,000 까지의 모든 소수를 구하는 프로그램
*/
#include <stdio.h>
#include <math.h>
void process(int end);
int main(int argc, char **argv) {
process(1000000);
getchar();
getchar();
return 0;
}
void process (int end) {
int i, j, temp, flag;
int count = 0;
if (end >= 2) {
//printf ("2
");
count++;
}
if (end >= 3) {
//printf ("3
");
count++;
}
for (i = 5; i < end; i+=2) {
temp = (int)sqrt(i);
flag = 0;
for (j = 3; j <= temp; j+=2) {
if (i % j == 0) {
flag = 1;
break;
}
}
if ( flag == 0) {
// printf ("%d
", i);
count++;
}
}
printf ("Total count : %d
", count);
}[/CODE]