Skip to content

Instantly share code, notes, and snippets.

@thiagodeschamps
Created November 6, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagodeschamps/88b317b67db597b4942211f1ecddb4fc to your computer and use it in GitHub Desktop.
Save thiagodeschamps/88b317b67db597b4942211f1ecddb4fc to your computer and use it in GitHub Desktop.
#include <stdio.h>
int ehprimo(int);
int main(void){
FILE *fp;
fp = fopen("testefileC.txt", "w");
int i = 0;
int qnt = 200000;
int num = 2;
while(i != qnt){
if(ehprimo(num)){
fprintf(fp, "%d\n", num);
i++;
}
num++;
}
fclose(fp);
}
int ehprimo(int x){
int i;
for(i = 2; i < x/2+1; i++){
if((x % i) == 0){
return 0;
}
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment