版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
********************************************************
0已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求出這些數(shù)中的各位數(shù)字之和是奇數(shù)的數(shù)的
個數(shù)totCnt,以及滿足此條件的這些數(shù)的算術平均值totPjz,最
后調用函數(shù)WriteDat。把所求的結果輸出到文件OUT1.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
include<stdio.h>
#include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti,n;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
/*求各位之和*/
n=xx[i]/1000+(xx[i]%1000)/100+(xx[i]%100)/10+xx[i]%10;
if(n&l){/*是奇數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累加和*/
)
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n");
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n",totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n",totCnt);
printf("平均值=%.2lf\n",totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
if((fp=fopenC'in.dat","r"))==NULL)return1;
while(!feof(fp)){
fscanf(fpz"%d,"z&xx[i++]);
}
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopenC'OUTl.DAT","w");
fprintf(fp,"%d\n%d\n%.2lf\n"ztotNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
1已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求出這些數(shù)中的各位數(shù)字之和是偶數(shù)的數(shù)的
個數(shù)totCnt,以及滿足此條件的這些數(shù)的算術平均值totPjz,最
后調用函數(shù)WriteDat()把所求的結果輸出到文件OUT2.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)
函數(shù)WriteDat()的內容。
include<stdio.h>
#include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti,n;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
/*求各位之和*/
n=xx[i]/1000+(xx[i]%1000)/100+(xx[i]%100)/10+xx[i]%10;
if((n&l)==0){/*是偶數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累力口和*/
}
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n");
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n",totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n",totCnt);
printf(“平均值=%.2lf\n“,totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
n
if((fp=fopen("in.dat"zr"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,"%d,",&xx[i++]);
)
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopen("OUT2.DAT","w");
fprintf(fp,"%d\n%d\n%.2lf\n",totNum,totCnt,totPjz);
fclose(fp);
)
2已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的iE整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)右移1位后,產(chǎn)生的新數(shù)是奇數(shù)的
數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)(右移前的值)的算術
平均值totPjz,最后調用函數(shù)WriteDat。把所求的結果輸出到文
件OUT3.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
//include<stdio.h>
#include<conio.h>
//defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
if((xx[i]?l)&1){/*右移1位后是奇數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=計算累力口和*/
)
)
}
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n”);
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)二%d個\n",totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
printf("平均值=%.2lf\n”,totPjz);
WriteDat();
intReadDat(void)
{
FILE*fp;
inti=0;
if((fp=fopenC'in.dat","r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,"%d,,&xx[i++]);
)
fclose(fp);
return0;
}
voidWriteDat(void)
(
FILE*fp;
fp=fopenC'OUTS.DAT","w");
fprintf(fp,"%d\n%d\n%.2lf\n",totNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
3已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)右移1位后,產(chǎn)生的新數(shù)是偶數(shù)的
數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)(右移前的值)的算術
平均值totPjz,最后調用函數(shù)WriteDat()把所求的結果輸出到文
件OUT4.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat()的內容。
include<stdio.h>
#include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
{
inti;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
if(((xx[i]?l)&1)==0){/*右移1位后是偶數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累加和*/
)
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf(“數(shù)據(jù)文件IN.DAT不能打開!\007\n”);
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)二%d個\n”,totNum);
print"'符合條件的正整數(shù)的個數(shù)二%d個\n,totCnt);
printf("平均值=%.2lf\n“,totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
if((fp=fopenC^n.dat","r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,&xx[i++]);
)
fclose(fp);
return0;
}
voidWriteDat(void)
(
FILE*fp;
fp=fopen("OUT4.DArz"w");
fprintf(fp,"%d\n%d\n%.2lf\n"ztotNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
4已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)中的個位數(shù)位置上的數(shù)字是3、
6利9的數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)的算術平均
值totPjz,最后調用函數(shù)WriteDat()把所求的結果輸出至I1文件
OUT5.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
include<stdio.h>
include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti,n;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0乂/*是正整數(shù)*/
totNum++;/*計數(shù)*/
n=xx[i]%]0;/*求個位*/
if(n&&(n%3)==0){/*個位是3的倍數(shù)且不為的亦即3、6、9*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累加和*/
)
}
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n");
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n,totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
printf("平均值=%.2lf\n“,totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
if((fp=fopenC'in.dat","r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,&xx[i++]);
)
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopenCOUTS.DAT","w");
u
fprintf(fp,%d\n%d\n%.2lf\n"ztotNum,totCnt,totPjz);
fclose(fp);
)
5已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2,求這些數(shù)中的十位數(shù)位置上的數(shù)字是2、
4和8的數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)的算術平均
值totPjz,最后調用函數(shù)WriteDat()把所求的結果輸出到文件
0UT6.DAT中。
注意:部分源程序存放在PR0G1.C中。
請勿改動主函數(shù)main().讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
include<stdio.h>
^include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
intizn;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
n=(xx[i]%100)/10;/*求十位數(shù)*/
if(n==211n==411n==8){/*十位數(shù)是2、4、8*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累加和*/
)
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
{
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n“);
return;
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n",totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n",totCnt);
printf("平均值=%.2lf\n",totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
if((fp=fopenC'in.daC"r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,&xx[i++]);
)
fclose(fp);
return0;
}
voidWriteDat(void)
(
FILE*fp;
fp=fopen(nOUT6.DAT","w");
fprintf(fp,"%d\n%d\n%.2lf\n"/totNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
6已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)中的百位數(shù)位置上的數(shù)字是1、
5和7的數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)的算術平均
值totPjz,最后調用函數(shù)WriteDat()把所求的結果輸出到文件
OUT7.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
//include<stdio.h>
ttinclude<conio.h>
//defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
intizn;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
n=(xx[i]%1000)/100;/*求百位數(shù)*/
if(n==l||n==5||n==7){/*百位數(shù)是1、5、7*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累加和*/
)
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf(“數(shù)據(jù)文件IN.DAT不能打開!\007\n");
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n“,totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
printf("平均值=%.2lf\n“,totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
,,
if((fp=fopen("in.dat/"r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,&xx[i++]);
)
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopen("OUT7.DAr,"w");
fprintf(fp,"%d\n%d\n%.2lf\n"ztotNum,totCnt,totPjz);
fclose(fp);
)
7已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)中的千位數(shù)位置上的數(shù)字大于個
位數(shù)位置上的數(shù)字的數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)
的算術平均值totPjz,最后調用函數(shù)WriteDat()把所求的結果輸
出到文件OUT8.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat。的內容。
include<stdio.h>
include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
if(xx[i]/1000>xx[i]%10){/*千位數(shù)大于個位數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累力口和*/
)
}
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf(“數(shù)據(jù)文件IN.DAT不能打開!\007\n”);
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)二%dtotNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
print"'平均值totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
if((fp=fopenC'in.dat'*,"r"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,"%d,,&xx[i++]);
)
fclose(fp);
return0;
voidWriteDat(void)
FILE*fp;
fp=fopen("OUT8.DAT","w");
fprintf(fp,"%d\n%d\n%.2lf\n",totNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
8已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
'數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:L求出這文件中共有多少
個正整數(shù)totNum;2.求這些數(shù)中的百位數(shù)位置上的數(shù)字小于十
位數(shù)位置上的數(shù)字的數(shù)的個數(shù)totCnt,以及滿足此條件的這些數(shù)
的算術平均值totPjz,最后調用函數(shù)WriteDat。把所求的結果輸
出到文件OUT9.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main()>讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)
函數(shù)WriteDat()的內容。
include<stdio.h>
ttinclude<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
if((xx[i]%1000)/100<(xx[i]%100)/10){/*百位數(shù)小于卜位數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+=xx[i];/*計算累力口和*/
)
)
)
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n");
return;
)
CalValue();
printf("文件IN.DAT中共有正整數(shù)=%d個\n”,totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
printf("平均值=%.2lf\n“,totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
n
if((fp=fopen("in.dat"zr"))==NULL)return1;
while(!feof(fp)){
fscanf(fp,"%d,",&xx[i++]);
)
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopen("OUT9.DAT'z"w");
fprintf(fp,"%d\n%d\n%.2lf\n",totNum,totCnt,totPjz);
fclose(fp);
)
9已知在文件IN.DAT中存有若干個(個數(shù)<200)四位數(shù)字的正整
數(shù),函數(shù)ReadDat()是讀取這若干個正整數(shù)并存入數(shù)組xx中。請
編制函數(shù)CalValue(),其功能要求:1.求出這文件中共有多少
個正整數(shù)totNum;2,求這些數(shù)中的千位數(shù)位置上的數(shù)字與十位
數(shù)位置上的數(shù)字均為的奇數(shù)的個數(shù)totCnt,以及滿足此條件的這
些數(shù)的算術平均值totP憶最后調用函數(shù)WriteDat。把所求的結
果輸出到文件OUT10.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)
函數(shù)WriteDat()的內容。
#include<stdio.h>
include<conio.h>
#defineMAXNUM200
intxx[MAXNUM];
inttotNum=0;/*文件IN.DAT中共有多少個正整數(shù)*/
inttotCnt=0;/*符合條件的正整數(shù)的個數(shù)*/
doubletotPjz=0.0;/*平均值*/
intReadDat(void);
voidWriteDat(void);
voidCalValue(void)
(
inti;
longent=0;
for(i=0;i<MAXNUM;i++){
if(xx[i]>0){/*是正整數(shù)*/
totNum++;/*計數(shù)*/
if((xx[i]/1000)&l&&((xx[i]%100)/10)&l){/*千位數(shù)和十位數(shù)均為奇數(shù)*/
totCnt++;/*統(tǒng)計個數(shù)*/
ent+二xx1];/*計算累力口和*/
)
)
}
totPjz=(double)ent/totCnt;/*計算平均值*/
voidmain()
(
inti;
clrscr();
for(i=0;i<MAXNUM;i++)xx[i]=0;
if(ReadDat()){
printf(“數(shù)據(jù)文件IN.DAT不能打開!\007\n”);
return;
)
CalValue();
printf(“文件IN.DAT中共有正整數(shù)二%d個\n,totNum);
printf("符合條件的正整數(shù)的個數(shù)=%d個\n”,totCnt);
printf(“平均值二totPjz);
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
n
if((fp=fopen("in.dat"zr"))==NULL)return1;
while(!feof(fp)){
fscanf(fpz"%dz",&xx[i++]);
}
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
fp=fopenC^UTlO.DAT","w");
fprintf(fpz"%d\n%d\n%.2lf\n",totNum,totCnt,totPjz);
fclose(fp);
)
********************************************************
10函數(shù)ReadDatO實現(xiàn)從文件ENG.IN中讀取一篇英文文章存入到
字符串數(shù)組xx中;請編制函數(shù)ComWord。分別計算出10個不區(qū)分大
小寫的英文單詞(you,for,your,on,no,if,the,in,to,all)的頻數(shù)
并依次存入整型數(shù)組yy⑼至yy[9]中,最后調用函數(shù)WriteDat()
把結果yy輸出到文件PS1,OUT中。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符,含
標點符號和空格。
注意:部分源程序存放在PROG1.C中。文章每行中的單詞與單
詞之間用空格或其它標點符號分隔,每單詞均小于20個字符。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)函
數(shù)WriteDat。的內容。
#include<stdio.h>
include<string.h>
#include<conio.h>
include<ctype.h>
,,',
charWORD[10][10]={"you","for","your","on","no"/"if",the"/"in"zto"/"all"};
charxx[50][80];/*xx存放上是一篇50行80列的文章*/
intyy[10];/*各元素對應10個單詞的頻度*/
intmaxline=0;/*文章的總行數(shù)*/
intReadDat(void);
voidWriteDat(void);
voidComWord(void)
(
intij;
charstr[80];/*存放從xx中臨時取出的一個單詞*/
char*pch;
for(i=0;i<10;i++)yy[i]=0;/*計數(shù)數(shù)組全部清0*/
for(i=0;i<50;i++){
pch=xx[i];/*指針pch指向這一行的行首*/
while(*pch){/*循環(huán)直到行結束*/
j=0;
while(isalpha(*pch))/*這個循環(huán)用于從當前行取出一個單詞,并存放于str中
*/
str[j++]=*pch++;
strU]=O;/*給字符串補上0*/
if(str[O]){/*不空*/
/*循環(huán)和WORD中的單詞——比較*/
for(j=0;j<10;j++){
if(stricmp(str,WORD[j])==0){/*找到*/
yy[j]++;/*計數(shù)*/
break;
)
)
}
pch++;
voidmain()
inti;
clrscr();
for(i=0;i<10;i++)yy[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007");
return;
)
ComWord();
WriteDat();
)
intReadDat(void)
(
FILE*fp;
inti=0;
char*p;
,,n
if((fp=fopen("eng.in/r"))==NULL)return1;
while(fgets(xx[i],80,fp)!=NULL){
p=strchr(xx[i],'\n*);
if(p)xx[i][p-xx[i]]=0;
i++;
}
maxline=i;
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
inti;
fp=fopen("psl.out"z"w");
for(i=0;i<10;i++){
,,
printf("%s=%d\n/strupr(WORD[i]),yy[i]);
fprintf(fp,"%d\n"zyy[i]);
)
fclose(fp);
)
11函數(shù)ReadDat()實現(xiàn)從文件ENG.IN中讀取一篇英文文章存入到
字符串數(shù)組xx中;請編制函數(shù)ComWord()分別計算出單詞長度3,5,
7,9的單詞數(shù)以及單詞總數(shù)并依次存入整型數(shù)組yy⑼至yy⑷中,
最后調用函數(shù)WriteDat。把結果yy輸出到文件PS2.0UT中。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符,含
標點符號和空格。
注意:部分源程序存放在PROG1.C中。文章每行中的單詞與單
詞之間用空格或其它標點符號分隔,每單詞均小于20個字符。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat()和輸出數(shù)據(jù)函
數(shù)WriteDat()的內容。
include<stdio.h>
include<string.h>
#include<conio.h>
include<ctype.h>
charxx[50][80];
intyy[5];
intmaxline=0;/*文章的總行數(shù)*/
intReadDat(void);
voidWriteDat(void);
voidComWord(void)
(
inti,n;
char*pch;
for(i=0;i<5;i++)yy[i]=0;/*數(shù)組yy全部清0*/
for(i=0;i<50;i++){
pch=xx[i];/*指針pch指向這一行的行首*/
while(*pch){/*循環(huán)直到行結束*/
if(isalpha(*pch))
yy[4]++;/*單詞計數(shù)*/
for(n=0;isalpha(*pch);pch++)n++;/*這個循環(huán)用于計算單詞的長度*/
if(n==311n==511n==711n==9)/*符合條件*/
yy[(n-3)/2]++;/*表達式(n?3)/2可以巧妙地求出下標值*/
pch++;/*跳過空格*/
)
}
voidmain()
inti;
clrscr();
for(i=0;i<5;i++)yy[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007");
return;
}
ComWord();
WriteDat();
intReadDat(void)
(
FILE*fp;
inti=0;
char*p;
if((fp=fopenC'eng.in","r"))==NULL)return1;
while(fgets(xx[i]z80,fp)!=NULL){
p=strchr(xx[i],'\n');
if(p)xx[i][p-xx[i]]=0;
i++;
)
maxline=i;
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
inti;
fp=fopen("ps2.out"/"w");
for(i=0;i<5;i++)fprintf(fp,"%d\n”,yy[i]);
printf("單詞長度為3的單詞數(shù)=%5己,yy[O]);
printf("單詞長度為5的單詞數(shù)=%5己,yy[l]);
printf(“單詞長度為7的單詞數(shù)=%5己,yy[2]);
printf(“單詞長度為9的單詞數(shù)二%d\n”,yy[3]);
printf("單詞的總數(shù)二%d\n”,yy[4]);
fclose(fp);
)
********************************************************
12函數(shù)ReadDat。實現(xiàn)從文件ENG.IN中讀取一篇英文文章存入到
字符串數(shù)組XX中;請編制函數(shù)ComWordO分別計算出單詞長度2,4,
6,8的單詞數(shù)以及單詞總數(shù)并依次存入整型數(shù)組yy⑼至yy⑷中,
最后調用函數(shù)WriteDat。把結果yy輸出到文件PS3.OUT中。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符,含
標點符號和空格。
注意:部分源程序存放在PR0G1.C中。文章每行中的單詞與單
詞之間用空格或其它標點符號分隔,每單詞均小于20個字符。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)函
數(shù)WriteDat()的內容。
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
charxx[50][80];
intyy[5];
intmaxline=0;/*文章的總行數(shù)*/
intReadDat(void);
voidWriteDat(void);
voidComWord(void)
(
inti,n;
char*pch;
for(i=0;i<5;i++)yy[i]=0;/*數(shù)組yy全部清0*/
for(i=0;i<50;i++){
pch=xx[i];/*指針pch指向這一行的行首*/
while(*pch){/*循環(huán)直到行結束*/
if(isalpha(*pch))
yy[4]++;/*單詞計數(shù)*/
for(n=0;isalpha(*pch);pch++)n++;/*這個循環(huán)用于計算單詞的長度*/
if(n==2||n==411n==6||n==8)/*符合條件*/
表達式可以巧妙地求出下標值*/
yy[n/2-l]++;/*n/2-l
pch++;/*跳過空格*/
)
)
voidmain()
(
inti;
clrscr();
for(i=0;i<5;i++)yy[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件ENG.IN不能打開!'n\007");
return;
)
ComWord();
WriteDat();
)
intReadDat(void)
(
FILE*fp;
inti=0;
char*p;
if((fp=fopenC'eng.in","r"))==NULL)return1;
while(fgets(xx[i],80,fp)!=NULL){
p=strchr(xx[i],'\n');
if(p)xx[i][p-xx[i]]=0;
i++;
)
maxline=i;
fclose(fp);
return0;
)
voidWriteDat(void)
(
FILE*fp;
inti;
fp=fopen("ps3.out"/"w");
for(i=0;i<5;i++)fprintf(fpz"%d\n"zyy[i]);
printf(“單詞長度為2的單詞數(shù)=%5己,yy[O]);
printf("單詞長度為4的單詞數(shù)=%5己,yy[l]);
printf("單詞長度為6的單詞數(shù)=%5己,yy[2]);
printf("單詞長度為8的單詞數(shù)=%5己,yy[3]);
printf("單詞的總數(shù)=%5己,yy[4]);
fclose(fp);
********************************************************
13函數(shù)ReadDat。實現(xiàn)從文件ENG.IN中讀取一篇英文文章存入到
字符串數(shù)組xx中;請編制函數(shù)ComWord。分別計算出10個不區(qū)分大
小寫的英文單詞的首字母也心抬八川^4向的頻數(shù)并依次存
入整型數(shù)組yy⑼至yy[9]中,最后調用函數(shù)WriteDat()把結果yy
輸出到文件PS4.0UT中。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符,含
標點符號和空格。
注意:部分源程序存放在PR0G1.C中。文章每行中的單詞與單
詞之間用空格或其它標點符號分隔,每單詞均小于20個字符。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)函
數(shù)WriteDat。的內容。
include<stdio.h>
include<string.h>
#include<conio.h>
include<ctype.h>
charWORD[11]={"bcfsnrueop"};
charxx[50][80];
intyy[10];
intmaxline=0;/*文章的總行數(shù)*/
intReadDat(void);
voidWriteDat(void);
voidComWord(void)
(
inti,j;
chare;
char*pch;
for(i=0;i<10;i++)yy[i]=0;/*數(shù)組yy全部清0*/
for(i=0;i<50;i++){
pch=指針pch指向這一行的行首*/
while(*pch){/*循環(huán)直到行結束*/
if(isalpha(*pch)){
c=*pch&Oxdf;/*單詞的首字母,"&Oxdf”可以轉換成大寫*/
for(j=0;j<10;j++){
if(c==(WORD[j]&Oxdf)){
yyU++]++;
break;
)
)
}
while(isalpha(*pch))pch++;/*這個循環(huán)用于將pch推進到下?單詞*/
pch++;/*跳過空格*/
)
)
}
voidmain()
(
inti;
clrscr();
for(i=0;i<10;i++)yy[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007");
return;
)
ComWord();
WriteDat();
}
intReadDat(void)
(
FILE*fp;
inti=0;
char*p;
if((fp=fopenC'eng.in","r"))==NULL)return1;
while(fgets(xx[i],80,fp)!=NULL){
p=strchr(xx[i],'\n');
if(p)xx[i][p-xx[i]]=0;
i++;
)
maxline=i;
fclose(fp);
return0;
voidWriteDat(void)
FILE*fp;
inti;
fp=fopen("ps4.out","w");
for(i=0;i<10;i++){
printf("%c=%d\n",WORD[i],yy[i]);
fprintf(fp,"%d\n",yy[i]);
)
fclose(fp);
}
********************************************************
14函數(shù)ReadDat()實現(xiàn)從文件ENG.IN中讀取?篇英文文章存入到
字符串數(shù)組xx中;請編制函數(shù)ComWord。分別計算出10個不區(qū)分大
小寫的英文單詞的尾字母伙,"50川?。刀)的頻數(shù)并依次存
入整型數(shù)組yy⑼至yy陰中,最后調用函數(shù)WriteDat()把結果yy
輸出到文件PS5.0UT中。
原始數(shù)據(jù)文件存放的格式是:每行的寬度均小于80個字符,含
標點符號和空格。
注意:部分源程序存放在PR0G1.C中。文章每行中的單詞與單
詞之間用空格或其它標點符號分隔,每單詞均小于20個字符。
請勿改動主函數(shù)main。、讀數(shù)據(jù)函數(shù)ReadDat。和輸出數(shù)據(jù)函
數(shù)WriteDat。的內容。
include<stdio.h>
include<string.h>
#include<conio.h>
include<ctype.h>
charWORD[11]={"kyfsnrueop");
charxx[50][80];
intyy[10];
intmaxline=0;/*文章的總行數(shù)*/
intReadDat(void);
voidWriteDat(void);
voidComWord(void)
(
intij;
chare;
char*pch;
for(i=0;i<10;i++)yy[i]=0;/*數(shù)組yy全部清0*/
for(i=0;i<50;i++){
pch=xx[i];/*指針pch指向這一行的行首*/
while(*pch){/*循環(huán)直到行結束*/
while(*pch&&!isalpha(*pch))pch++;/*去掉前面的空格*/
while(*pch&&isalpha(*pch))pch++;/*這個循環(huán)用于將pch推進到單詞的末尾
*/
c=*(pch-l)&Oxdf;/*pch-:l.指向末尾的字符,"&Oxdf”可以轉換成大寫*/
for(j=0;j<10;j++){
if(c==(WORD[j]&Oxdf)){
yy[]++]++;
break;
}
}
)
)
voidmain()
(
inti;
clrscr();
for(i=0;i<10;i++)yy[i]=0;
if(ReadDat()){
printf("數(shù)據(jù)文件ENG.IN不能打開!\n\007");
return;
)
ComWord();
WriteDat();
)
intReadDat(void)
(
FILE*fp;
inti=0;
char*p;
if((fp=fopen("eng.in","r"))==NULL)return1;
while(fgets(xx[i],80,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 金融模型輕量化訓練方法
- 2025年河北省公需課學習-《中華人民共和國快遞暫行條例》條文詳解
- 2025年八大特殊作業(yè)安全知識考試題及答案(共60題)
- 單招汽車專業(yè)題庫及答案
- 第六單元 第26課時 圓的基本性質
- 2025年中職語文專題試卷及答案
- 工地材料運輸合同范本
- 2025年鹿邑初三二模試卷及答案
- 2025年隧道橋梁考試題庫及答案
- 樓頂屋頂改造合同范本
- 鋁板拆除施工方案
- 三角形的內角和與外角和教案
- 植入式靜脈給藥裝置(輸液港)-中華護理學會團體標準2023
- 0031預防成人經(jīng)口氣管插管非計劃性拔管護理專家共識
- THMSRX型實訓指導書
- 原發(fā)性支氣管肺癌教案
- 教練場地技術條件說明
- JJG 229-2010工業(yè)鉑、銅熱電阻
- GB/T 23280-2009開式壓力機精度
- 金壇區(qū)蘇教版六年級上冊數(shù)學第6單元《百分數(shù)》教材分析(定稿)
- pid管道及儀表流程圖總集
評論
0/150
提交評論