>8441
6722
6603
6545
6323
6181
4369
4285
4125
2724
2362
之八
要求:
把千位数字和十位数字重新组成一个新的十位数ab(新
十位数的十位数字是原四位数的千位数字,新十位数的个位数字
是原四位数的十位数字), 以及把个位数字和百位数字组成另一
个新的十位数cd (新十位数的十位数字是原四位数的个位数字,
新十位数的个位数字是原四位数的百位数字), 如果新组成的两
个十位数ab 同时两个新数的十位数字均不为零,则将满足此条件的四位数按
从大到小的顺序存入数组b中, 并要计算满足上述条件的四位数
的个数cnt。
out.dat 的内容应当为:
12
7878
5437
3897
2893
2877
2438
2039
2035
2033
1619
1494
1493
之九
要求:
如果四位数各位上的数字均是奇数,则统计出满足此条
件的个数cnt并把这些四位数按从大到小的顺序存入数组b中。
out.dat 的内容应当为:
13
9971
7973
7711
7511
5755
5359
5311
3575
3537
3135
1997
1979
1531
之十
要求:
把千位数字和十位数字重新组成一个新的十位数ab(新
十位数的十位数字是原四位数的千位数字,新十位数的个位数字
是原四位数的十位数字), 以及把个位数字和百位数字组成另一
个新的十位数cd (新十位数的十位数字是原四位数的个位数字,
新十位数的个位数字是原四位数的百位数字), 如果新组成的两
个十位数ab-cd>=0且ab-cd<=10且两个数均是奇数, 同时两个新
数的十位数字均不为零,则将满足此条件的四位数按从大到小的
顺序存入数组b中, 并要计算满足上述条件的四位数的个数cnt。
out.dat 的内容应当为:
5
8398
7996
5954
4313
2311
小于200个四位数之一(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整
数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2.求出这些数中的各位数字之和是奇数的数的个
数totCnt, 以及满足此条件的这些数的算术平均值totPjz。最后
main( )函数调用函数WriteDat()把所求的结果输出到OUT.DAT文
件中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WriteDat()的内容。
*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */
int totCnt = 0 ; /* 符合条件的正整数的个数 */
double totPjz = 0.0 ; /* 平均值 */
int ReadDat(void) ;
void WriteDat(void) ;
void Calvalue(void)
{/**/
while(xx[totNum])
{ if((xx[totNum]/1000+xx[totNum]/100%10+xx[totNum]/10%10+xx[totNum])%2)
{ totCnt++; totPjz+=xx[totNum]; }
totNum++;
}
if(totCnt) totPjz/=totCnt;
/**/
}
void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < MAXNUM ; i++) xx[i] = 0 ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!07n") ;
return ;
}
Calvalue() ;
printf("文件IN.DAT中共有正整数=%d个n", totNum) ;
printf("符合条件的正整数的个数=%d个n", totCnt) ;
printf("平均值=%.2lfn", totPjz) ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
fp = fopen("OUT.DAT", "w") ;
fprintf(fp, "%dn%dn%.2lfn", totNum, totCnt, totPjz) ;
fclose(fp) ;
}
in.dat 文件内容如下:
6045,6192,1885,3580,8544,6826,5493,8415,3132,5841,
6561,3173,9157,2895,2851,6082,5510,9610,5398,5273,
3438,1800,6364,6892,9591,3120,8813,2106,5505,1085,
5835,7295,6131,9405,6756,2413,6274,9262,5728,2650,
6266,5285,7703,1353,1510,2350,4325,4392,7573,8204,
7358,6365,3135,9903,3055,3219,3955,7313,6206,1631,
5869,5893,4569,1251,2542,5740,2073,9805,1189,7550,
4362,6214,5680,8753,8443,3636,4495,9643,3782,5556,
1018,9729,8588,2797,4321,4714,9658,8997,2080,5912,
9968,5558,9311,7047,6138,7618,5448,1466,7075,2166,
4025,3572,9605,1291,6027,2358,1911,2747,7068,1716,
9661,5849,3210,2554,8604,8010,7947,3685,2945,4224,
7014,9058,6259,9503,1615,1060,7787,8983,3822,2471,
5146,7066,1029,1777,7788,2941,3538,2912,3096,7421,
9175,6099,2930,4685,8465,8633,2628,7155,4307,9535,
4274,2857,6829,6226,8268,9377,9415,9059,4872,6072,
out.dat 文件内容应当如下:
160
69
5460.51
小于200个四位数之二(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整
数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2.求出这些数中的各位数字之和是偶数的数的个
数totCnt, 以及满足此条件的这些数的算术平均值totPjz。最后
main( )函数调用函数WriteDat()把所求的结果输出到OUT.DAT文
件中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WriteDat()的内容。
*/
#include
#include
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */
int totCnt = 0 ; /* 符合条件的正整数的个数 */
double totPjz = 0.0 ; /* 平均值 */
int ReadDat(void) ;
void WriteDat(void) ;
void Calvalue(void)
{/**/
for(; xx[totNum]; totNum++)
if((xx[totNum]/1000+xx[totNum]/100%10+xx[totNum]/10%10+xx[totNum]%10)%2==0)
{ totCnt++; totPjz+=xx[totNum];}
if(totCnt) totPjz/=totCnt;
/**/
}
void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < MAXNUM ; i++) xx[i] = 0 ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!07n") ;
return ;
}
Calvalue() ;
printf("文件IN.DAT中共有正整数=%d个n", totNum) ;
printf("符合条件的正整数的个数=%d个n", totCnt) ;
printf("平均值=%.2lfn", totPjz) ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
fp = fopen("OUT.DAT", "w") ;
fprintf(fp, "%dn%dn%.2lfn", totNum, totCnt, totPjz) ;
fclose(fp) ;
}
out.dat 文件内容应当如下:
160
91
5517.16
200个四位数之三(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整
数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2. 求这些数右移1位后, 产生的新数是奇数的数
的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平
均值totPjz。最后main()函数调用函数WriteDat()把所求的结果
输出到文件OUT.DAT中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WriteDat()的内容。
*/
#include
#include
#define MAXNUM 200
int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */
int totCnt = 0 ; /* 符合条件的正整数的个数 */
double totPjz = 0.0 ; /* 平均值 */
int ReadDat(void) ;
void WriteDat(void) ;
void Calvalue(void)
{/**/
for(; xx[totNum]; totNum++)
if((xx[totNum]>>1)%2)
{ totCnt++; totPjz+=xx[totNum];}
if(totCnt) totPjz/=totCnt;
/**/
}
void main()
{
int i ;
clrscr() ;
for(i = 0 ; i < MAXNUM ; i++) xx[i] = 0 ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!07n") ;
return ;
}
Calvalue() ;
printf("文件IN.DAT中共有正整数=%d个n", totNum) ;
printf("符合条件的正整数的个数=%d个n", totCnt) ;
printf("平均值=%.2lfn", totPjz) ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
fp = fopen("OUT.DAT", "w") ;
fprintf(fp, "%dn%dn%.2lfn", totNum, totCnt, totPjz) ;
fclose(fp) ;
}
out.dat 文件内容应当如下:
160
80
5537.54
小于200个四位数之四(共四题)
code:
/*
已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整
数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编
制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个
正整数totNum; 2. 求这些数右移1位后, 产生的新数是偶数的数
的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平
均值totPjz。最后main()函数调用函数WriteDat()把所求的结果
输出到文件OUT.DAT中。
注意: 部分源程序存放在PROG1.C中。
请勿改动数据文件IN.DAT中的任何数据,主函数main()、读
数据函数ReadDat()和输出数据函数WriteDat()的内容。
*/
#include
#include
#define MAXNUM 200
int xx[MAXNUM] ;