已知数据文件IN.dat中存有200个四位数,并已调用读函数rData()把这些数存入数组a中,请编写函数spellNum(),其功能是:把个位数字和千位数字重新组成一个新的二位数(新二位数的十位数字是原四位数的个位数字,新二位数的个位数字是原四位数的千位数字),以及把百位数字和十位数字组成另一个新的二位数(新二位数的十位数字是原四位数的百位数字,新二位数的个位数字是原四位数的十位数字),如果新组成的两个二位数一个是奇数,另一个为偶数,并且两个二位数中至少有一个数能被17整除,同时两个新数的十位数字均不为0,则将满足此条件的四位数按从大到小的顺序存入数组b中,并要计算满足上述条件的四位数的个数count。最后main()函数调用写函数wData(),把结果count以及数组b中符合条件的四位数输出到OUT.dat文件中。
#include
#define MAX 200
int a[MAX], b[MAX], count = 0;
void spellNum()
{ int i, thou, hun, ten, data, j;
int ab, cd;
for (i=0; i<200; i++)
{ thou = a[i]/1000;
hun = a[i]%1000/100;
ten = a[i]%100/10;
data = a[i]%10;
if (data==0 || hun==0)
continue;
ab = 10*data+thou;
cd = 10*hun+ten;
if ((ab-cd)%2!=0 && (ab*cd)%17==0)
{ b[count] = a[i];
count++;
}
}
for (i=0; i
{ data = b[i];
b[i] = b[j];
b[j] = data;
}
}
void rData()
{ int i;
FILE *fp;
fp = fopen("IN.dat", "r");
for (i=0; i
fclose(fp);
}
void wData()
{ FILE *fp;
int i;
fp = fopen("OUT.dat", "w");
fprintf(fp, "%d\n", count);
for (i=0; i
fclose(fp);
}
void main()
{ int i;
rData();
spellNum();
printf("满足条件的数=%d\n", count);
for (i=0; i
printf("\n");
wData();
}
文件中的内容:2161,4523,4568,2300,4169,3342,5648,5538,7784,9482,
6785,8794,8162,8972,4353,2561,1397,3746,5284,4632,
8535,8806,4098,1234,2348,4745,8964,7829,7896,1456,
6748,4268,7896,4856,8634,7428,7589,4869,1236,7542,
4853,7869,8534,4333,4523,8674,7141,8711,2253,7868,
8547,1644,6662,4785,3037,4569,9723,1741,1529,1778,
4316,2456,5190,4698,1288,4106,8967,9942,2446,5648,
1446,7896,1258,7412,4568,7350,7006,7524,7393,4548,
2629,4623,7084,2954,1756,3840,5966,8376,5931,9308,
8944,4583,7568,3323,9632,7567,6116,7789,5573,4421,
5833,5115,5639,3658,5704,1930,5977,3306,5673,5386,
6021,2745,8888,2072,7472,6829,9777,7573,6097,8512,
9444,7444,1161,1636,5555,7767,6655,7574,5031,4052,
5327,2150,8941,4724,5966,9934,5107,4191,1007,3337,
7457,4287,5864,2383,6945,5786,6209,1758,4226,4565,
7422,7946,1506,5030,8413,3168,1900,6591,1762,2655,
9410,7359,1624,3537,4548,7483,1595,5041,4602,7350,
2291,4836,1374,3020,5596,7021,1348,6199,2668,7484,
9281,5734,1053,2999,9418,1938,7900,4788,1127,1467,
4728,6893,7648,5483,9807,3421,6310,7617,5813,1514,
去我百度空间翻,里面有我以前课设时候弄得设备管理系统,很简单的那种。