问题 多项选择题

已知数据文件IN77.DAT中存有200个4位数,并已调用读函数readDat()把这些数存入数组a中,请编制一函数jsVal(),其功能是:如果一个4位数的干位数字上的值加十位数字上的值恰好等于百位数字上的值加上个位数字上的值,并且此4位数是偶数,则统计㈩满足此条件的数的个数cnt并把这些4位数按从小到大的顺序存入数组b中,最后调用写函数writeDat()把结果cnt及数组b中符合条件的4位数输出到OUT77. DAT文件中。
注意:部分源程序已给出。
程序中已定义数组:a[200], b[200], 已定义变量:cnt。
请勿改动主函数main()、读函数readDat()和写函数writeDat()的内容。
试题程序:
#include<stdio. h>
#define MAX 200
int a[MAX] ,b[MAX] ,cnt=0;
void jsVal( )


void readDat ( )

int i;
FILE *fp;
fp=fopen ( "IN77. 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 ( "OUT7 7. DAT", "w" );
fprint f (fp, "%od\n", cnt);
for (i=0;i<cnt; i++)
fprintf(fp, "%d\n",b[i]);
fclose (fp);

答案

参考答案:void jsVal( )
{
int i, thou, hun, ten, data, j;
int ab, cd;
for (i=0; i<MAX; i++)
{
thou=a [i]/A000; /*求四位数的千位数字*/
hun=a [i] %A000/A00; /*求四位数的百位数字*/
ten=a [i] %A00/A0; /*求四位数的十位数字*/
data=a [i] %A0; /*求四位数的个位数字*/
if ((thou+ten==hun+data) &&a [i] %B !=A)
{ /*如果千位数加十位数等于百位数,并且此数是偶数*/
b [cnt]=a [i]; /*则将满足条件的数存入数组b中*/
cnt++; /*统计满足条件的数的个数*/
}
}
for (i=0; i<cnt-A; i++) /*将数组b中的数按从小到大的顺序排列*/
for (j=i+A; j<cnt; j++)
if (b[i]>b[j])
{
da ta=b [i];
b[i]=b[j];
b [j] =data;
}
}

解析: 本题考查的知识点如下:
(1)将一个4位整数各位上的数转变成单独的个位数。
(2)判断结构中多个条件的布尔运算。
(3)数据的排序。
在本题中,首先要将一个4位数的千位、百位、十位、个位拆成独立的数字。这里借助特殊运算符号“%” (取余)和“/” (整除)。将一们位数整除1000则可得到其千位上的数字,除以1000取余再整除100则可得百位上的数字,除以100取余再整除10则可得—卜位上的数字,除以10取余则得个位上的数字。若一个数除以2取余为0,则这个数是偶数。题目中的两个条件必须同时满足,所以两条件之间用“与”运算。先将满足条件的数存入数组b中,再对数组中的数据进行排序。最后的排序采用“选择排序法”。

阅读理解

What will the house of the future look like? Architects (建筑师) believe that there are all possibilities. The only thing for sure is that the house will be as green as possible.

The tree house

Many architects in the world would like to build a “tree house.” Like a leaf, the surface (表面) of the house collects sunlight during the day. The energy can be used to heat water, produce electricity, and even create fresh air for the home. The “root” of the house is deep under the ground.

The lizard (蜥蜴) house

Like a lizard, changing color with the weather is the most important design of a lizard house. When it’s in the bright sun, the cover of the house will turn dark to protect it from strong heat. During dark days, it turns white and takes in as much light and heat as possible to produce energy.

Meals at home

It has gardens on the outside wall of the house. People can plant tomatoes, carrots and green tea on them. So every day in the morning, you just need to walk outside and collect your meals.

Learning from the past

Looking to the future isn’t the only way to be green. Sometimes, ancient techniques (古老的技术) can also help cut down energy use. For example, a chimney can be a useful air conditioner because it is easier for hot air to flow out at the chimney.

小题1:We can heat water, produce electricity or create fresh air for the home _________.

A.with a leaf from the tree

B.with the energy from sunlight

C.with gardens on its wall

D.with the door in the house小题2:What will happen to the cover of the lizard house when it’s in the bright sun?

A.It will take in light.

B.It will produce energy.

C.It will turn dark.

D.It will turn white.小题3:People can’t plant __________ on the outside wall of the house according to the passage.

A.tomatoes

B.potatoes

C.carrots

D.green tea小题4: What’s the passage mainly about?

A.Future life

B.Green house of the future

C.Different houses

D.Energy saving in the future

填空题