问答题
在文件IN3.DAT中有200个正整数,且每个数均在1000至9999之间。函数readDat()的功能是读取这200个数存放到数组aa中。请编制函数jsSort(),该函数的功能是:要求按每个数的后3位的大小进行降序排列,将排序后的前10个数存入数组b中,如果数组b中出现后3位相等的数,则对这些数按原始4位数据进行升序排列。最后调用函数writeDat()把结果bb输出到文件OUT3.DAT中。例如:处理前 9012 5099 6012 7025 8088处理后 5099 8088 7025 6012 9012注意:部分源程序已给出。请勿改动主函数main()、读函数readDat()和写函数writeDat()的内容。试题程序:#include
#include
#include
int aa[200], bb[10];void jsSort(){}main(){readDat();jsSort();writeDat();}readDat(){FILE *in;int i;in = fopen("IN3.DAT", "r");for(i = 0; i < 200; i++) fscanf(in, "%d,", &aa[i]);fclose(in);}writeDat(){FILE *out;int i; out = fopen("OUT3.DAT", "w");clrscr();for (i = 0; i < 10; i++){printf("i=%d,%d\n", i + 1, bb[i]);fprintf(out, "%d\n", bb[i]);}fclose(out);}
【参考答案】
void jsSort(){int i,j,data;for(i=0;i
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
单项选择题
A.Once a week.B.Twice a week.C.Three times a week.D.Four times a week.
A.Once a week.
B.Twice a week.
C.Three times a week.
D.Four times a week.
点击查看答案
单项选择题
A.Washing plates.B.Cleaning tables.C.Shining shoes.D.Sweeping the floor.
A.Washing plates.
B.Cleaning tables.
C.Shining shoes.
D.Sweeping the floor.
点击查看答案
相关试题
A.David doesn’t like having snakes...
A.telegraphB.invitationC.exhibitionD...
A.Yes, I’m afraid so.B.Of cours...
A.She wanted to know the time.B....
A.Allow me to go out with Mr. J...