Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #define RANGE 10000u
- #define SCMAX (RANGE/3)
- // compiled with cl65 -r -O -Cl crivello.c -o crivello.prg
- typedef unsigned char uint_8;
- uint_8 composite[RANGE];
- int main(void) {
- clock_t Ticks, TicksDelta;
- unsigned int Sec;
- unsigned int Milli;
- unsigned int pi=0;
- unsigned int pr=0;
- register unsigned int i;
- register unsigned int j=2;
- register unsigned int ScopeMax;
- for(j=0,i=1; j<RANGE; ++j) {
- composite[j]=0;
- composite[i]=1;
- ++j;
- i+=2;
- }
- j=3;
- ScopeMax = RANGE/j;
- printf("\nPress enter to start\n");
- //getchar();
- printf("\nComputing...\n");
- Ticks = clock();
- while(j<SCMAX) {
- pr=j+j+j-1;
- for (i=3; i<=ScopeMax; i+=2) {
- composite[pr]=1;
- pr+=j+j;
- }
- j+=2;
- 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