问题 问答题

已知数据文件IN53.DAT中存有200个4位数,并已调用读函数readDat()把这些数存入数组a中,请编制一函数JsVal(),其功能是:依次从数组a中取出一个4位数,如果该4位数连续大于该4位数以前的5个数且该数是偶数,则统计出满足此条件的数个数cnt并把这些4位数按从大到小的顺序存入数组b中,最后调用写函数writeDat()把结果cnt及数组b中符合条件的4位数输出到文件OUT53.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("in53.dat","r");
for(i=0;i<MAX;i++)
fscanf(fp,"%d",&a[i]);
fclose(fp);

void main()

int i;
readDat();
jsVal();
print f ( "满足条件的数=%d\n", cnt);
for(i=0;i<cnt;i++)
printf("%d",b[i]);
printf("\n");
writeDat ( );

writeDat ()

FILE *fp;
int i;
fp=fopen("out53.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;

for (i=E; i<MAX; i++ )

{

for (j=i-E; j<i;j++)

{

if(a[i]>a[j]) /*如果该D位数连续大于它以前的E个数*/

flag=l; /*则置flag为A*/

else flag=0; /*否则置flag为0*/

if (a[i]%B!=0) /*如果该四位数为奇数*/

flag=0; /*则置flag为0*/

if (flag==0)

break; /*如果flag为0, 则退出循环*/

}

if (flag==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] )

{

flag=b[i];

b[i]=b[j];

b[j]=flag;

}

}

解析:

本题考查的知识点如下:

(1)使用循环对数组的元素进行比较和排序。

(2)强行退出循环结构。

在本题中,数组b中的数据要满足的条件有两个。在这里,不再使用判断结构中条件的布尔运算,而采用一种新的方法——设置标志变量flag。当数据不满足某一条件时,如数据不是偶数,将flag设置为0:当flag等于0时,可直接退出本层循环结构,进入外层的循环中。否则,根据题意要求,将数据存入数组b中。对数组b中的数据排序,使用“选择排序法”。

阅读理解

阅读理解。

     If you go to Brisbane, Australia, you can easily get a small book called "Discover Brisbane" free.

The book tells you almost everything in Brisbane: the restaurants, the shops, the cinemas, the streets,

the buses, the trains, the banks, etc. Here is something about on page 49:

     ANZ Banking Group

     Corner of Greek & Queen Streets…………………………………228 3228

    Bank of New Zealand

    410 Queen Street…………………………………………………221 0411

     Bank of Queensland

     229 Elizabeth Street………………………………………………229 3122

    Commonwealth Banking Group

    240 Queen Street…………………………………………………237 3111

    National Australia Bank Ltd.

    225 Adelaide Street………………………………………………221 6422

    Westpac Banking Corp.

    260 Queen Street…………………………………………………227 2666

    Banking Hours:

    Mon.--Thurs. 9:30 a.m. to 4 p.m.

    Fri.9:30 a.m. to 5 p.m.

    All banks close Sat. Sun. & Public Holidays.

1. From the material, we can know ______.

A. Brisbane is a city in Australia        

B. "Discover Brisbane" is expensive  

C. "Discover Brisbane" has about 49 pages    

D. "Discover Brisbane" tells you everything in Brisbane

2. You can find Bank of Queensland on ______

A. Queen Street                

B. Elizabeth Street

C. Adelaide Street          

D. the corner of Greek Street and Queen Street

3. ______ seems to be the banking center in Brisbane.

A. Greek Street            

B. Elizabeth Street

C. Queen Street            

D. Adelaide Street

4. At 5:30 p.m., you can go to ______  to put your money in or take your money out.

A. no banks        

B. ANZ Banking Group 

C. National Australia Bank Ltd.    

D. Commonwealth Banking Group

5. In Australia, the banks have their longest service hours on ______.

A. Fridays    

B. Mondays and Thursdays    

C. weekends    

D. public holidays

单项选择题