Last active
November 6, 2016 09:42
-
-
Save CykuTW/a4994eb380b443c425765e897530212a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //run on Microsoft Visual Studio 2015 Express | |
| #define _CRT_SECURE_NO_WARNINGS | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| #define SIZE 1000001 | |
| unsigned char table[SIZE]; | |
| int main(void) { | |
| clock_t t1, t2; | |
| int i, j, n; | |
| printf("Pleas enter an integer between 2 and 1,000,000\n"); | |
| scanf("%d", &n); | |
| //start timer | |
| t1 = clock(); | |
| //initialize | |
| table[0] = table[1] = 0; | |
| for (i = 0; i <= n; i++) | |
| table[i] = 1; | |
| //create table | |
| for (i = 2; i <= n; i++) | |
| if (table[i]) | |
| for (j = 2; j*i <= n; j++) | |
| table[j*i] = 0; | |
| //output result | |
| for (i = 2; i <= n; i++) | |
| if (table[i]) | |
| printf("%d\n", i); | |
| //stop timer | |
| t2 = clock(); | |
| printf("execution time: %lf s\n", (t2 - t1) / (double)(CLOCKS_PER_SEC)); | |
| system("PAUSE"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment