Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #define TRUE 1
- #define FALSE 0
- int l, n, m, lim;
- char* nums;
- char input[255];
- clock_t start, stop;
- int main()
- {
- printf("Enter a limit for this search: ");
- gets(input);
- lim = atoi(input);
- start = clock();
- nums = (char *)malloc(lim);
- for (n = 2; n < sqrt(lim); n++)
- {
- if (nums[n] == FALSE)
- {
- m = n * n;
- while (m <= lim)
- {
- nums[m] = TRUE;
- m += n;
- }
- }
- }
- stop = clock();
- printf("It took %f seconds.\n", (double)(stop - start) / 1000);
- system("pause");
- for (n = 2; n < lim; n++)
- {
- if (nums[n] == FALSE)
- printf("%d\n", n);
- }
- free(nums);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement