Skip to content

Instantly share code, notes, and snippets.

@freetstar
Created November 23, 2012 09:46
Show Gist options
  • Save freetstar/4134803 to your computer and use it in GitHub Desktop.
Save freetstar/4134803 to your computer and use it in GitHub Desktop.
寻找质数
#include <stdio.h>
int main(int argc, const char *argv[])
{
int max = 100;
int num = 0;
int a[100];
for(int i=0;i<max;i++)
{
int j=2;
while(j<i)
{
if(i%j!=0)
j++;
else
break;
}
if(j==i)
{
a[num]=i;
num++;
}
}
for(int n=0;n<num;n++)
printf("%d\n",a[n]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment