~cpp
/* prime2.c */
#include <stdio.h>
#include <time.h>
#define MAX_PRIME 50000
int main(void) {
int i, j, flag, arr_p, tmp;
int arr[10000] = {0, };
time_t start, end;
start = clock();
arr[0] = 2;
arr_p = 1;
for (i = 3; i < MAX_PRIME; i += 2) {
for (j = 0, flag = 1, tmp = i >> 1; tmp >= arr[j]; j++) {
if (i % arr[j] == 0) {
flag = 0;
break;
}
}
if (flag) {
arr[arr_p] = i;
arr_p++;
}
}
i = 0;
end = clock();
while (arr[i] != 0)
printf("%d ", arr[i++]);
printf("\n%f\n", (double)(end - start) / CLK_TCK);
return 0;
}