问题 问答题

请编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k传回。
例如:若输入17,则应输出9和4,6,8,9,10,12,14,15,16。
注意:部分源程序在文件PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
文件PROG1.C内容如下:
#include<stdio.h>
void fun(int m,int *k,int xx[])


void main( )
int m,n,zz[100];
printf("\nPlease enter an integer number between 10 and 100:");
scanf("%d",&n);
fun(n,&m,zz);
printf("\nThere are%d non-prime numbers less than%d:\n",m,n);
for(n=0;n<m;n++)printf("%4d",zz[n]);
printf("\n"):

答案

参考答案:void fun(int m,int *k,int xx[]){
int i,j,n=0;
for(i=2;i<m;i++){
for(j=2;j<=i/2;i++)
if(i%j==0) break;
if(j<=i/2) {
xx[n]=i;n++;
}
}
*k=n;
}

解析: 本题虽然是要求求出非素数,实际也是考查素数的判定算法。对于变量i取出的每一个值,变量j都从2开始循环到i/2,在变量j的这个范围内,能找到一个j,i能够整除它,则i是非素数,将i赋值到数组xx中。循环结束后,将数组的长度n赋值给*k,通过指针k带回数组xx的长度。
[归纳总结] 本套试题的程序填空和程序设计题考查的是素数的判定算法。考题中通常要求对某个范围内的素数进行一定的处理。此类题目的常用程序段如下:
for(i=m;i<=n;i++){ /*求出m到n之间的素数*/
for(j=2;j<=i/2;j++)
if(i%j==0)break;
if(j>i/2){
…/*若条件成立,则i是素数,根据程序要求补充后面的语句*/
}

阅读理解

Hana al—Shaibani was born on August 27, 1942.She was the only girl in her family, having two older and two younger brothers.Her father, a politician and journalist, loved her and played a large role in shaping the woman she grew up to be.

In 1956, Iraq's Baath party started to grow in popularity.Its slogans declaring liberty, Arab socialism and unity attracted the younger generation, including Hana.Although she was only 14 years old, she turned member of the party-receiving her education with her political activities.During her university years, she worked for the Baath party during the day and attended classes in the evening.

In 1958, following the overthrow of Iraq's monarchy (君主政治) , Hana rose through the ranks and was chosen to lead the party's female members.She was just 16.Two years later, she was selected as one of three representatives of the Iraqi Baath party to attend the Arab National Baath Party Conference, held that year in Beirut.Still just a teenager, she had already achieved more than most women from her region could ever imagine.

As was known to everyone, she was determined and fearless.One of the most memorable family stories tells of the time in 1959 when she left the house to join an organization against the rule of the then prime minister, Abdel Karim Qassim.The atmosphere was tense and a number of the organisers would later be killed.But Hana was determined to attend.

Sensing trouble, she hid the gun and carried beneath her skirt as she walked down the stairs.Her father begged with her not to go.He explained that as a patriot he understood her sense of duty, but added that his love for her went beyond all else.Hana replied; "Papa, you were once a patriotic man and when you were called upon to fight, you did.Please understand, so that I may go with your blessing rather than without." Her father could not stop her.

小题1:.The passage mainly talks about __    __.

A.the life of Hana al-Shaibani       

B.the achievement of Hana al-Shaibani

D.the sufferings Hana al-Shaibani has received

D.Hana al-Shaibani and her father

小题2:.When Hana al-Shaibani joined the Baath party, __    __.

A.she had to abandon her studies

B.she became popular with the people

C.she attracted the younger generation

D.she was then only a student小题3:.From the third paragraph we can know that _     ___.

A.Hana stood up tor Iraq's monarchy totally

B.Hana was strongly against the old government

C.Hana defeated more women older than her

D.Hana was made Chairwoman of the party小题4:.The passage is developed in the order of ___     _.

A.place

B.progress

C.time

D.space

单项选择题