Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Created April 22, 2014 02:53
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 ktnyt/11163902 to your computer and use it in GitHub Desktop.
Save ktnyt/11163902 to your computer and use it in GitHub Desktop.
かんたんな素数列挙
#include <stdio.h>
int isPrime(int n) {
int i;
for(i = 2; i * i <= n; ++i) {
if(n % i == 0) {
return 0;
}
}
return 1;
}
int main() {
int i, j, f;
for(i = 2; i < 100; ++i) {
if(isPrime(i)) {
printf("%d\n", i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment