#include <stdio.h>
#define N 100
int is_zhishu(int);
int main(int argc, int *argv[])
{
int a[N];
int i = 0,j,k = 0;
do
{
a[i] = i+1;
i++;
}while(i < N);
for(i = 0; i < N; i++)
{
if (1 == is_zhishu(a[i]))
{
for (j = i + 1; j < N; j++)
{
if (0 == a[j])
{
continue;
}
else if (0 == a[j] % a[i])
{
a[j] = 0;
}
else
{
;
}
}
}
else
{
a[i] = 0;
}
}
for (i = 0; i < N; i++)
{
if (0 == a[i])
{
continue;
}
else
{
if (k != 0 && 0 == k % 5)
{
printf("\n");
}
k++;
printf("%d ",a[i]);
}
}
printf("\nall %d numbers.\n",k);
system("pause");
return 0;
}
int is_zhishu(int number)
{
if (number < 1)
{
return 0;
}
if (1 == number)
{
return 0;
}
if (2 == number)
{
return 1;
}
int i,result = 1;
for (i = 2; i < number; i++)
{
if (0 == number % i)
{
result = 0;
break;
}
}
return result;
}
|