问题 问答题

文件IN.DAT中存有200个4位整型数,函数ReadData()负责将IN.DAT中的数读到数组inBuf[]中。请编写函数findValue(),其功能是:求出千位数字上的值加十位数字上的值等于百位数字上的值减上个位数字上的值,并且此4位数是偶数的数,用count记录下符合条件的数的个数并按照从小到大的顺序存入数组outBuf[]中。函数WriteData()负责将outBuf[]中的数输出到文件OUT.DAT中并且在屏幕上显示出来。
注意:部分源程序已给出。
程序中已定义数组:inBuf[200],outBuf[200],已定义变量:count。
请勿改动主函数main()、读函数ReadData()和写函数WriteData()的内容。

试题程序:


#include<stdio.h>
#define NUM 200
int inBuf[NUM],outBuf[NUM],count=0;
void readData();
void writeData();
void findValue()


void main()

int i:
readData();
findValue();
writeData();
printf("count=%d\n",count);
for(i=0;i<count;i++)
printf("outBuf[%d]=%d\n",i,outBuf[i]);

void readData( )

FILE*fp;
int i;
fp=fopen("IN.DAT","r");
for(i=0;i<NUM;i++)
fscanf(fp,"%d,",&inBuf[i]);
fclose(fp);

void writeData()

FILE*fp;
int i:
fp=fopen("OUT.DAT","w"):
fprintf(fp,"count=%d\n",count);
for(i=0;i<count;i++)
fprintf(fp,"%d,\n",outBuf[i]);
fclose(fp);

答案

参考答案:void findValue()
{
int i,j,k,d[4],temp;
for(i=0;i<NUM;i++)
{
for(j=0;j<4;j++)
{
temp=inBuf[i]; //将要进行分解的数据存入temp中
for(k=0;k<j;k++)temp=temp/10;//求第j位的值时
d[3-i]=temp%10; //先将temp除以10的i次方,再对其求余即可
}
if(d[0]+d[2]==d[1]-d[3]&&d[3]%2==0)
{
outBur[count]=inBuf[i];
count++:
}
}
for(i=0;i<count-1;i++) //以下是将数据进行从小到大排序的程序
for(j=i+1;j<count;j++)
if(outBuf[i]>outBuf[j]) //如果第i位比它后面的数大,则将两者进行交换,也即将更小的值放到第i位
{
temp=outBuf[i];
outBuf[i]=outBur[j];
outBuf[j]=temp;
}
}

解析: 本题主要考查数位分解及排序。
数位分解就是将n位数上各个位上的数值单独分离出来。解决此问题的方法是:将n位数对10求余可以将个位上的数值分离出来。将这个n位数除以10以后得到一个n-1位数,则此时n位数原来的十位就变成了n-1位数的个位,再将此n-1位数对10求余便可得到原n位数的十位。依次类推,按照同样的方法便可将n位数各个位上的数值分离出来。
程序步骤:①将数值送入temp中;②由temp%10得到个位数,(temp/10)%10得到十位数……如此可得到各位上的数值;③按照题目所给的条件选出数据;④对选出的数据进行排序,排序的思想是(以从小到大为例),将当前数据与其后的各个数据相比较,如果当前的数据比其后的数据大,则将两数据进行交换,从而使得前面的数据小于后面的数据,达到从小到大排序的目的。

完形填空

阅读下面短文并回答问题,然后将答案写到答题卡相应的位置上(请注意问题后的词数要求)。

[1] People of all ages and races can serve as volunteers. They work in various organizations without pay. Volunteering improves your life and the lives of others. You can meet new people and make a positive difference in the world.

[2] Volunteers generally work with others either as part of a team completing a project or caring for other people such as patients in a nursing home or helping children through an organization such as Big Brothers, Big Sisters. Volunteers should be generally cheerful and easy to work with and have a positive attitude even if things are not satisfactory in their own lives.

[3] Some volunteers organize events or groups of people to work on various projects. Without their good organizational skills, these projects might not happen. For example, if you’re the Parent-Teacher Association President for your school, you will be responsible for organizing the individual committees in your school. If you have good organizational skills, volunteering will become less stressful and you can give back to your community in the way you intended.

[4] Volunteers have to be willing to devote a certain amount of hours each week or month depending on the situation. It is necessary for them to go through testing or training before they begin volunteering. The best volunteers do what they say they’re going to do and show up when they say they’re going to be there unless there are situations beyond their control.

[5] Good volunteers see the good in others, whether it’s the people they’re working with or the people they’re serving. These volunteers generally go beyond what they’re asked to do because they want to get to know the people they’re serving. They go beyond surface relationships by remembering names, information and stories told to them. Volunteers that are healthy and well-balanced will bring that feeling to the environment, and the people they’re helping will be affected.

小题1:What is the best title of the text? (no more than 5 words)

___________________________________________________________

小题2:List three benefits of being a volunteer mentioned in the text. (no more than 20 words)

___________________________________________________________

小题3:What must volunteers do before they begin volunteering? (no more than 8 words)

___________________________________________________________

小题4:Which quality of a volunteer do you think is the most important? Why? (no more than 30 words)

___________________________________________________________

小题5:How do volunteers respond when they find their life unsatisfactory? (no more than 6 words)

___________________________________________________________

单项选择题

2005年某地农村居民收入的变动

2005年农村居民人均纯收入为2476元,比上年同期增加109元。其中,农村居民外出务工得到的收入人均为438.2元,比上年同期增长11.6%。打工收入增长主要是由于农村居民外出打工人数继续大幅度增加。2005年,外出打工人数增加了12.2%。2004年,由于粮食价格的回升,农村居民从事农业生产经营的收入扭转了持续三年下降的局面,2005年,在粮食、生猪等主要农产品价格下降的情况下,农村居民从事农业生产经营得到的收入人均为1135元,比上年增加8.5元,增长0.8%。在2005年农村居民的农业收入中,种植业收入人均808元,比上年下降 0.2%;牧业收入211元,下降0.6%;林业收入26元,比上年增长15.5%;渔业收入32元,增长 11.5%;其他农业收入59元,增长近5%。2005年,从事二、三产业生产经营得到的收入人均为 351.5元,比上年增加18.5元,增长5.5%。2005年,农村居民的税费负担人均为78.7元,比上年减少12.5元。由于税费负担下降,直接拉动农村居民收入增长0.5个百分点。

下列结论可以推出的是()。

①2005年从事牧业收入占农村居民人均出收入的比重为8.5%。

②2005年从事农业生产经营得到的收入是从事二、三产业生产经营得到的收入的3倍多。

③2005年税费负担占农村居民人均纯收入的比重为3.2%。

A.只有①

B.只有②

C.②和③

D.①、②和③