用筛选法可得到2-n(n<10000)之间的所有素数,

用筛选法可得到2-n(n<10000)之间的所有素数,方法是:首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所有倍数;依此类推,直到所找的下一个数等于n为止。这样会得到一个序列:

2,3,5,7,11,13,17,19,23,....

函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。

请在程序的下划线处填入正确的内容,使程序得出正确的结果。

不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
int fun(int n)
{
	int a[10000], i, j, count=0;
	for (i=2; i<=n; i++)
	{
		a[i] = i;
	}
	i = 2;
	while (i<n)
	{
		/**********found**********/
		for (j=a[i]*2; j<=n; j+=__(1)__)
		{
			a[j] = 0;
		}
		i++;
		/**********found**********/
		while (__(2)__==0)
		{
			i++;
		}
	}
	printf("\n 2 到 %d 的素数有:\n", n);
	for (i=2; i<=n; i++)
	{
		/**********found**********/
		if (a[i]!=__(3)__)
		{
			count++; 
			printf(count%15?"%5d":"\n%5d",a[i]);
		}
	}
	return count;
}
main()
{
	int n=30, r;
	r = fun(n);
	printf("\n素数的个数为:%d\n", r);
	system("pause");
}


答案
第1空:a[i]
第2空:a[i]
第3空:0

题目信息

题号:6706
题型:填空题
难度:普通