4coder/non-source/test_data/sample_files/primes.cpp

30 lines
577 B
C++
Raw Normal View History

2018-03-16 18:19:11 +00:00
#include <stdlib.h>
#include <stdio.h>
void list_primes(int *primes, int max){
int j = 0;
int x = 2;
while (j < max){
int composite = false;
for (int i = 0; i < j; ++i){
if (x % primes[i] == 0){
composite = true;
}
break;
}
if (!composite){
primes[j++] = x;
}
}
}
int main(){
int *primes = malloc(1000*sizeof(int));
list_primes(primes, 1000);
for (int i = 0; i < 1000; ++ i){
printf("%d\n", primes[i]);
}
return(0);
}