试卷详情 三级网络技术机试-212 [多项选择]已知数据文件IN.DAT中存有300个四位数,并已调用读函数readDat( )把这些数存入数组a中,请编制一个函数jsValue( ),其功能是:求出千位数上的数加百位数上的数等于十位数上的数加个位数上的数的个数.cnt,再把所有满足此条件的四位数依次存人数组b中,然后对数组b的四位数按从大到小的顺序进行排序。最后main( )函数调用写函数writeDat( )把数组b中的数输出到文件OUT.DAT中。 例如,7153,7+1=5+3,则该数满足条件存入数组b中,且个数cnt=cnt+1。 8129,8+1!=2+9,则该数不满足条件忽略。 注意:部分源程序存在文件PROG1.C文件中。程序中已定义数组:a[300],b[300],已定义变量:cnt。请勿改动数据文件IN.DAT中的任何数据、主函数main( )、读函数readDat( )和写函数writeDat( )的内容。 [试题程序] #include int a[300],b[300],cnt=0; void readDat( ); void writeDat( ); jsValue( ); main( ) int i; readDat( ); jsValue( ); writeDat( ); printf(“cnt=%d/n”,cnt); for(i=0;i<cnt;i++) printf(“b[%d]=%d/n”,i,b[i]); void readDat( ) FILE *fp; int i; to=fopen("in.dat","r"); for(i=0;i<300;i++) fscanf(fp,“%d,”,&a[i]); fclose(fp); void writeDat( ) FILE *fP; int i; fp=fopen("out.dat","w"); fprintf(fp,“%d/n”,cnt);