Code:
#include <stdio.h>
int main()
{
long int a[100000];
int i, j, k, sw;
int l=0;
for (i = 0; i<100000; i++)
a[i] = 0;
for (j = 3; j<10000; j++)
{
for (k = 2, sw = 1; k<j; k++)
if ((j % k) != 0)
sw = 0;
if (sw = 0)
{
a[l] = j;
l++;
}
}
return 0;
}
I'm trying to compute prime numbers up to 10000 and store them in the a-array. the algorithm is simple, it checks to see whether j can be divided to any integer between 1 and itself.
if it wasn't possible to do that it would assign 0 to sw. if sw was 0 it means j is a prime number hence it gets stored in the a-array.
this doesn't work. I'm guessing it has some logical error.
I would appreciate it if someone could help me out.