I have written a simple program in C to find all prime numbers within a given range using Sieve of Eratosthenes. In school, we are currently learning assembly in a class, but I can't figure out how to write the three loops. I have somewhat figured it out in NASM, which I have fiddled with before, but we have to use AT&T. Any suggestions what I can do with "void sieve()"?
#include <stdio.h>
#include <stdlib.h>
void sieve(int *, int);
int main()
{
int *a, n, i;
n = 46000;
printf("Enter the range : ");
scanf("%d", &n);
a = malloc(sizeof(int)*n);
sieve(a,n);
printf("\nThe primes numbers from 1 to %d are: ", n);
for(i=2; i<=n; i++)
{
if(a[i] == 1)
printf("%d, ", i);
}
printf(".\n\n");
return 0;
}
void sieve(int *a, int n)
{
int i, j;
for(i=2; i<=n; i++)
a[i] = 1;
for(i=2; i<=n; i++)
{
if(a[i] == 1)
{
for(j=i; (i*j)<=n; j++)
a[(i*j)] = 0;
}
}
}