问题 多项选择题

已知数据文件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中,再对数组中的数据进行排序。最后的排序采用“选择排序法”。

单项选择题
阅读理解

阅读理解。

     Before a new type of airplane goes into service,every part of it

is tested again and again. But there are two tests that are more

important than all the others.

        The first is called the" tank test". A modern airplane must fly

very high in the sky. Air must be pumped into the plane so that the

passengers can breathe. The metal structure(结构) of the plane has

to be very strong for this reason. When the plane is filled with air,

the air presses against the skin of the plane inside. The pressure (压

力) on a small window is like a huge foot that is trying to get out. If

a small part of the plane were to fail,the plane would explode in the

sky. To test the structure of the plane, the plane is lowered into a

huge tank or container of water. Then it is filled with air. The pressure

inside the plane is greater than it ever will be when it is high

up in the air. Finally,there is an explosion. This does not cause so

much damage inside the water tank as it would anywhere else.

Engineers can discover which part of the plane has broken. Then that

part is made stronger.

     The most dangerous test happens when the new plane is going

through test flights in the air. The test pilot must find out exactly

what happens when the engines(发动机) are all shut off at once.

The plane begins to fall like a stone. It is the pilot's job to find out

how he can get control of the plane again. These two tests are

examples of how planes are made safe before they ever carry passengers.

1. By doing the"tank test" ,the engineers can find out___. 

A. the amount of air in the plane

B. the strength of the plane structure

C. the pressure inside and outside the plane

D. the power of the airplane engines

2. What will happen to the plane under the "tank test" ?     

A. It will be broken.

B. It will be made stronger.

C. It will be filled with water.

D. It will be tested by pilots.

3. According to the text,why are test flights most dangerous?   

A. The plane may explode in the air.

B. The pilot may lose control of the plane.

C. The engines may be damaged.

D. Too much air may get into the plane.

4. What might be the most suitable title for the text?  

A. Two Important Tests on Airplanes.

B. The Importance of Flying Safely.

C. The Danger of Testing Airplanes.

D. How Airplanes Are Made and Tested.