2,3,5,7,11,13,17,19,23,……
函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
int fun(int n)
{int a[10000], i,j, count=0;
for (i=2; i<=n; i++) a[i] = i;
i = 2;
while (i
/**********found**********/
for (j=a[i]*2; j<=n; j+=___1___)
a[j] = 0;
i++;
/**********found**********/
while (___2___==0)
i++;
}
printf("\nThe prime number between 2 to %d\n", n);
for (i=2; i<=n; i++)
/**********found**********/
if (a[i]!=___3___)
{count++; printf(count "]": "\n]",a[i]);}
return count;
}
main()
{int n=20, r;
r = fun(n);
printf("\nThe number of prime is : %d\n", r);
}
解题答案:
/**********第一空**********/
for (j=a[i]*2; j<=n; j+=a[i])
/**********第二空**********/
while (a[i]==0)
/**********第三空**********/
if (a[i]!=0)
******************************************
相关专题:
编辑推荐: