Created
January 21, 2016 03:40
-
-
Save Wingless-Archangel/6bd9c3995aceae149145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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