问题 问答题

已知数据文件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 jsVa1( )


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();
jsVa1();
printf("满足条件的数=%d\n",cnt);
for(i=0;i<cnt;i++)
printf("%d",b[i]);
printf("\n");
writeDat();

writeDat()

FILE *fp;
int i;
fp=fopen("OUT77.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,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])

{

data=b[i];

b[i]=b[j];

b[j]=data;

}

}

解析:

本题考查的知识点如下:

(1) 将一个4位整数各位上的数转变成单独的个位数。

(2) 判断结构中多个条件的布尔运算。

(3) 数据的排序。

在本题中,首先要将一个4位数的千位、百位、十位、个位拆成独立的数字。这里借助特殊运算符号“%”(取余)和“/” (整除)。将一个4位数整除1000则可得到其千位上的数字,除以1000取余再整除100则可得百位上的数字,除以100取余再整除10则可得十位上的数字,除以10取余则得个位上的数字。若一个数除以2取余为0,则这个数是偶数。题目中的两个条件必须同时满足,所以两条件之间用“与”运算。先将满足条件的数存入数组b中,再对数组中的数据进行排序。晕后的排序采用“选择排序法”。

完形填空
完形填空。
     Why    1    children go to school? Do you know? You may    2    that they go to school to learn Chinese,
English, and    3    subjects. This answer is    4    But do you know    5    they learn all these things? And are
these things all that they can learn    6    school?
     The answer is "No". Children must learn how to learn at school. No one can learn     7    from school.
When they    8    school they must continue (继续) to learn. So a good teacher at school    9    his students
to learn something and teaches them how to learn something and the ways to learn something. Then children
can continue to learn   10   after they leave school.
( )1.A.can       
( )2.A.say       
( )3.A.the others
( )4.A.right     
( )5.A.which     
( )6.A.at       
( )7.A.something          
( )8.A.leave     
( )9.A.teach     
( )10.A.well     

B.do        
B.speak  
B.other      
B.easy      
B.what      
B.to        
B.anything            
B.over      
B.teaches   
B.nice    

C.are             
C.tell         
C.another        
C.hard           
C.why            
C.for            
C.everything    
C.go to                                         
C.teaching      
C.good         
单项选择题 A1/A2型题