问题 多项选择题

已知数据文件IN15.DAT中存有200个4位数,并已调用读函数readDat() 把这些数存入数组a中。请编制函数jsVal(),其功能是:依次从数组a中取出一个4位数,如果该4位数连续小于该4位数以后的5个数且该数是偶数,则统计出满足此条件的数的个数cnt,并把这些4位数按从小到大的顺序存入数组b中,最后调用写函数writeDat()把结果cnt及数组b中符合条件的4位数输出到OUT15.DAT文件中。注意:部分源程序已给出。程序中已定义数组:a[200],b[200],已定义变量:cnt。请勿改动主函数main()、读函数readDat()和写函数writeDat()的内容。试题程序:#include#define MAX 200int a[MAX], b[MAX], cnt = 0; void jsVal(){}void readDat(){int i;FILE *fp;fp = fopen("IN15.DAT", "r");for(i = 0; i < MAX; i++) fscanf(fp, "%d", &a[i]);fclose(fp);}main(){int i;readDat();jsVal();printf("满足条件的数=%d\n", cnt);for(i = 0; i < cnt; i++)printf("%d ", b[i]);printf("\n");writeDat();}writeDat(){FILE *fp;int i;fp = fopen("OUT15.DAT", "w");fprintf(fp, "%d\n", cnt);for(i = 0; i < cnt; i++)fprintf(fp, "%d\n", b[i]);fclose(fp);}

答案

参考答案:void jsVal(){int i,j,flag=0;for (i=0;i

解析:根据题意可知,要编制函数的功能有两部分:一是找出满足条件的4位数;二是对找出的数进行从小到大排序。首先利用一个for循环来依次从数组中取得4位数,接着用当前得到的4位数与该数后面的5个数(可以用循环次数来控制)依次进行比较,如果该数比它后面的5个数都小,则给标志变量flag赋值1。接着对flag进行判断,如果不为1,则该数肯定不符合条件,直接去取下一个数;若flag值为1,再来判断该数是否是偶数,如果恰好该数又是偶数,则把该数加入到数组b中。这样就可以依次取出符合条件的数,然后利用选择法对b数组中的元素进行从小到大的排序。

阅读理解

阅读理解。

     What is the best way to study? This is a very important question. Some of the Chinese students often

 study very hard for long hours. This is a good habit, but it is not a better way to study. I think an efficient

 (有效率的 ) student must have enough sleep, enough food and enough rest. Every day you need to go

 out for a walk. Every week you should visit some friends or some nice places. It's good for your study.

 When you return to your studies, you'll find yourself stronger than before and you'll learn more.

        Some people say that learning English is like taking Chinese medicine. It means that like Chinese

  medicine, the effect of study comes slowly but surely.

1. _____ often study very hard for long hours.

    A. All the Chinese students

    B. Some of the Chinese students

    C. Any of the Chinese students

    D. Only a few Chinese students

2. An efficient student must have_____.

    A. enough sleep      

    B. enough food

    C. enough rest        

    D. A,B and C

3. Every day you need to _____, It's good for your study.

    A. go for a walk

    B. visit some friends

    C. visit some nice places

    D. eat some meat

4. "... learning English is like taking Chinese medicine " means ._____.

    A. it's very terrible

    B. it's wonderful

    C. the effect of study comes slowly but surely

    D. the effect of study comes quickly and surely

5. This passage mainly tells us _____.

    A. you should study hard for long hours

    B. you shouldn't sleep all night

    C. the proper (适当的) way to study

    D. the best way to keep healthy.