Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #define RANGE 10000u
- typedef unsigned char uint_8;
- uint_8 composite[RANGE];
- int main(void) {
- clock_t Ticks, TicksDelta;
- unsigned int Sec;
- unsigned int Milli;
- unsigned int i;
- unsigned int j=2;
- unsigned int pi=0;
- unsigned int pr=0;
- unsigned int ScopeMax;
- unsigned int ScopeMaxMax;
- for(j=0; j<RANGE; ++j) {
- composite[j]=0;
- }
- ScopeMax = RANGE/2;
- ScopeMaxMax= ScopeMax;
- printf("\nPress enter to start\n");
- getchar();
- printf("\nComputing...\n");
- Ticks = clock();
- j=2;
- while(j<ScopeMaxMax) {
- pr=j;
- for (i=2; i<=ScopeMax; ++i) { pr=pr+j; composite[pr-1]=1;}
- ++j;
- ScopeMax=RANGE/j;
- }
- TicksDelta = clock() - Ticks;
- Sec = (unsigned short) (TicksDelta / CLOCKS_PER_SEC);
- Milli = ((TicksDelta % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
- printf ("Time used: %u.%03u seconds = %u ticks\n", Sec, Milli, (unsigned short) TicksDelta);
- printf("Press enter to print the prime numbers\n");
- getchar();
- printf("\n");
- composite[0]=1;
- composite[1]=0;
- for(i=0; i<RANGE; ++i) {
- if(composite[i]==0) {
- ++pi;
- printf(" %u ", i+1);
- }
- }
- printf("\nPi = %u", pi);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement