问题 填空题

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

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

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

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

注意:源程序存放在考生文件夹下的BLANK1.C中。

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

 

答案

参考答案:a[i]

解析:

本题中fun函数的功能是用筛选法可得到2~n(n<10000)之间的所有素数,和一般的直接判断一个数是否是素数不同,一般的判断数n是否是素数的方法是比较从2开始的所有小于n的i,看n%i是否均不为0。筛选法是首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所有倍数;依此类推,直到所找的下一个数等于n为止,这样就可以将所有的非素数去除,剩下来的非0数就是素数。

第一空:循环“:for(j=a[i]*2;j<=n;j+=())”中,循环变量j的初始值从a[i]的2倍开始,下一次进入循环j就是a[i]的3倍,第一空处是补充j的变化情况,而j每次都增加一个a[i],即第一空处应为“a[i]”。

第二空:根据题意第二空处是从数表中找下一个非0数,即在循环中比较a[i]是否为,如果为0的话,i++指向后一个数表元素,故第二空处应为“a[i]”。

第三空:根据语句“{count++;printf(count%15"%5d":"\n%5",a[i]); }”可知在满足条件之后计数变量count自增,并且输出a[i],可知a[i]是一个素数,由审题分析可知,经过筛选之后数表中非0的元素就是素数,故第三空处应为“0”,即a[i]不为0的话就是素数。

[考点] 函数功能。

单项选择题
单项选择题

Burkina Faso student teacher Hema Cecile has a lot more time to crack the books thanks to a recent initiative from the World Bank and the International Finance Corporation (IFC). The launch of the Lighting Africa program by the two organizations this year has made it possible for Cecile to swap kerosene lamps for a solar-powered LED lantern.

Lighting Africa is a $12 million project which intends to bring light to the poorest regions across sub-Saharan Africa. The program works with the lighting industry to develop clean, affordable lighting and energy solutions for millions without access to electric grids. Its aim is to accelerate the market and to develop education programs that inform off-grid populations currently dependent on costly, inefficient and hazardous fuel-based lighting about modern alternatives.

Cecile used to spend $3-4 a month on kerosene for her lamp. That is a large proportion of her earnings—like 70 percent of the population she lives on less than $2 a day. In the weeks since buying her lantern she has managed to read four books including Madame Bovary. by Gustave Flaubert and Emile Zola’s Germinal. She is among the most learned in a society which has the world’s lowest literacy rate, according to a 2007 UN Human Development Report. When she graduates next year she will teach in a local junior school She makes ends meet by holiday jobs as a cleaner and an IT trainer. To earn her daily ration of cornmeal she does shifts from May to September in a corn field.

The lanterns are designed to look like the kerosene ones they are replacing in order to increase adoption among the population. Each has a small solar panel on the top and costs an average $30, although some cost $100, depending on the size of the battery and the number of LED lights it contains.

Because of the large number of sunlight hours in Burkina Faso, the lamps can be relied on to work whenever needed. The battery life is 2-4 years, and can be replaced once they lose their storage capacity. The LED lights last 5-10 years.

Although it is barely out of its trial period the project, Chabanne said there are signs the project is a boon for the population in areas other than household savings and education. "There are fewer people reporting eye problems to the local hospital.

What does the author think about the future of the project mentioned in this passage()

A. Uncertain

B. Optimistic

C. Pessimistic

D. Worried