Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active December 16, 2015 14:39
Show Gist options
  • Save fliiiix/5449964 to your computer and use it in GitHub Desktop.
Save fliiiix/5449964 to your computer and use it in GitHub Desktop.
Do What The Fuck You Want To Public License
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define MAX 80000000
//Sieb des Eratosthenes zur bestimmung von primzahlen
int Sieb_des_Eratosthenes()
{
long long unsigned int i, j, x;
x = 0;
char *array;
array = calloc((MAX + 1), sizeof(char));
if (array==NULL) {
printf("Error allocating memory!\n");
return -1; //return with failure
}
for(i = 2; i <= sqrt(MAX); i++)
{
if(array[i] == 0)
{
for(j = i * i; j <= MAX; j += i)
{
array[j] = 1;
}
}
}
for(i = 2; i <= MAX; i++) {
if (array[i] == 0) {
x++;
}
}
printf("Primzahlen: %d\n", x);
free(array);
array = NULL;
return 0;
}
int main(void)
{
LARGE_INTEGER frequency;
LARGE_INTEGER start;
LARGE_INTEGER end;
double interval;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
Sieb_des_Eratosthenes();
QueryPerformanceCounter(&end);
interval = (double) (end.QuadPart - start.QuadPart) / frequency.QuadPart;
printf("%f\n", interval);
system("PAUSE");
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment