Skip to content

Instantly share code, notes, and snippets.

@Wingless-Archangel
Created January 21, 2016 03:40
Show Gist options
  • Save Wingless-Archangel/6bd9c3995aceae149145 to your computer and use it in GitHub Desktop.
Save Wingless-Archangel/6bd9c3995aceae149145 to your computer and use it in GitHub Desktop.
‪#‎include‬ <stdio.h>
‪#‎define‬ PRIME_SIZE 20
void primenum(int *pPrimeArray, int nSize)
{
pPrimeArray[0] = 2;
for (int i = 1; i<nSize; i++)
{
int j;
int n = pPrimeArray[i-1]; // last prime
do
{
for (j = 0; j<i; j++)
{
if (n%pPrimeArray[j]==0)
{
n++;
break;
}
}
} while (j<i);
pPrimeArray[i] = n;
}
}
void main()
{
int a[PRIME_SIZE];
primenum(a, PRIME_SIZE);
for (int i = 0; i<PRIME_SIZE; i++) printf("%d, ", a[i]);
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment