问题 问答题

已知数据文件IN.dat中存有200个四位数,并已调用读函数Rdata()把这些数存入数组a中,请编写函数NumCal(),其功能是:把一个四位数的千位数字上的值加上个位数字上的值恰好等于百位数字上的值加上十位数字上的值,并且原四位数是奇数,则统计出满足此条件的个数count并把这些四位数按从小到大的顺序存入数组b中。最后调用写函数Wdata(),把结果count以及数组b中符合条件的四位数输出到OUT.dat文件中。
注意:部分源程序已经给出。程序中已定义数组a[200] b[200],已定义变量count。请勿改动数据文件IN.dat中的任何数据及主函数main()、读函数Rdata()和写函数Wdata()的内容。
#include <stdio.h>
#define MAX 200
int a[MAX], b[MAX], count = 0;
void NumCal ()void Rdata ()
int i;
FILE *fp;
fp = fopen("IN. dat", "r");
for (i=0; i<MAX; i++)
fscanf(fp, "%d,", &a[i]);
fclose (fp);void Wdata ()
FILE *fp;
int i;
fp = fopen("OUT. dat", "w");
fprintf(fp, "%d\n", count);
for (i=0; i<count; i++)
fprintf(fp, "%d\n", b[i]);
fclose (fp);void main ()
int i;
Rdata ();
NumCal ();
printf("满足条件的数=%d\n", count);
for (i=0; i<count; i++)
printf("%d ", b[i]);
printf ("\n");
Wdata ();

答案

参考答案:

void NumCal()

{ int i, thou, hun, ten, data, j;

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 +data == hun +ten) && a[i]%B==A)

{ b[count] = a[i];

count++;

}

}

for (i=0; i<count-A; i++)

for (j=i+A; j<count; j++)

if (b[i] >b[j])

{ data = b[i];

b[i] = b[j];

b[j] = data;

}

}

解析:

[解题思路] 对于每一个四位数,用这个四位数除以1000,可得到这个四位数千位上的数字输给变量thou;这个四位数对1000求余数然后再除以100,可得到这个四位数百位上的数字输给变量hun;这个四位数对100求余数然后再除以10,可得到这个四位数十位上的数字输给变量ten;这个四位数对10求余数,可得到这个四位数个位上的数字输给变量data。

然后判断表达式(thou+ data==hun+ ten) &&a[i]%2=1是否成立,如果成立,则把这个数赋给数组b,同时计数变量count加1。最后对数组b中元素进行从小到大的排序。

完形填空
完形填空。
     Hearing the front door open, I ran down to the kitchen and waited. I saw my dad come in, with the white
envelope in his hand. I had waited all day for this, so I reached over him for it as soon as he set foot into the
house. Angrily, he   1   the envelope on the table and said that it was nothing to get excited about, and that it
was just a piece of paper. I grabbed (抓取) it and ran upstairs. I wondered why my dad did not understand
how   2   I was to see my mid-year report card for my first year in middle school. I was really   3   by how
he refused to consider all my hard work.
     I saw my class rank (等级): 1/139. I did not behave what I saw. I felt my lips (嘴唇) form a smile and
wanted to run downstairs to tell everyone. Then I   4   what my dad had said-it was nothing to get excited
about. I wanted to share my happiness with someone, but felt lonely.
     I realized that I had become distant (远隔的) from my family. We used to   5   late watching Disney movies,
and my brothers, sisters and I would play tennis in the backyard all the time. I wondered when all that had   6  .
I just no longer took part in them. My school work   7   all my time and energy.
     While I had been busy with my study, I had also built a   8   between me and my family. I was only trying
to become a person everyone could be   9   of.
     I wanted to go downstairs, say sorry for my rude behavior and for every refused movie and tennis game,
and be  10  of my family again, I knew I had to do something-because without their support, my achievement
meant nothing.
( )1. A. caught      
( )2. A. anxious     
( )3. A. beaten      
( )4. A. remembered  
( )5. A. come back   
( )6. A. begun       
( )7. A. set up      
( )8. A. wall        
( )9. A. famous      
( )10. A. hope       

B. cleaned up  
B. scared          
B. hurt        
B. realized        
B. go down       
B. stopped       
B. gave up        
B. bridge         
B. careful      
B. pride      

C. pinked up   
C. sad           
C. bothered   
C. forgot      
C. stay up      
C. improved    
C. used up        
C. road          
C. proud     
C. child   
D. threw      
D. frustrated    
D. troubled    
D. listened to                 
D. keep out    
D. appeared    
D. put up        
D. house        
D. afraid      
D. part       
单项选择题