这道C程序题怎么编(提示:用数组编)
1.用筛选法求100之内的素数.
2.用选
参考答案://下面是筛选法
#include <stdio.h>
int main()
{
int arr[101];
int mark[101];
int i, j, t;
for (i = 2; i < 101; i++)
{
arr[i] = i;
mark[i] = 1;
}
for (i = 2; i < 101;)
{
for (j = i + 1, t = arr[i]; j < 101; j++)
if (arr[j]%t == 0)
mark[j] = 0;
while ( ++i < 101 && mark[i] == 0);
}
for (i = 2; i < 101; i++)
if (mark[i])
printf("%d\t", arr[i]);
return 0;
}