




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、题目91(整数统计运算题)请编制程序prog1.c,从文件in.dat中读取200个整数至数组xx中,求出奇数的个数cnt1和偶数的个数cnt2以及数组xx下标为偶数的元素值的算术平均值pj(保留2位小数)。结果cnt1,cnt2,pj输出到out.dat中。部分程序、读数据函数read_dat(int xx200)及输出格式已给出。#include #include #define n 200void read_dat(int xxn)int i,j;file *fp;fp=fopen(in.dat,r);for(i=0;i20;i+) for(j=0;j10;j+) fscanf(fp,%
2、d,&xxi*10+j); printf(%d ,xxi*10+j);printf(n);fclose(fp);void main()int i,j,sum;int cnt1,cnt2,xxn;float pj;file *fw;clrscr();fw=fopen(out.dat,w);read_dat(xx);/*/sum=0; pj=0.0; cnt1=cnt2=0;for(i=0;in;i+) if(xxi%2) cnt1+; else cnt2+; if(i%2=0) pj+=xxi;sum+;pj/=sum;/*/printf(nncnt1=%d,cnt2=%d,pj=%6.2fn,
3、cnt1,cnt2,pj);fprintf(fw,%dn%dn%6.2fn,cnt1,cnt2,pj);fclose(fw);*题目92(整数统计运算题)请编制程序prog1.c,从文件in.dat中读取200个整数至数组xx中,求出最大数max及最大数的个数cnt和数组xx中能被3整除或能被7整除的算术平均值pj(保留2位小数)。结果max,cnt,pj输出到out.dat中。部分程序、读数据函数read_dat(int xx200)及输出格式已给出。#include #include #define n 200void read_dat(int xxn)int i,j;file *fp;f
4、p=fopen(in.dat,r);for(i=0;i20;i+) for(j=0;j10;j+) fscanf(fp,%d,&xxi*10+j); printf(%d,xxi*10+j);printf(n);fclose(fp);void main()int m,temp,n,sum;int cnt,xxn,max ;float pj;file *fw;clrscr();fw=fopen(out.dat,w);read_dat(xx);/*/cnt=0; max=xx0; pj=0.0; n=0;for(m=0;mn;m+) if(maxxxm) max=xxm;for(m=0;mn;m+)
5、 if(xxm=max) cnt+; if(xxm%3=0|xxm%7=0) pj+=xxm; n+; pj/=n;/*/printf(nnmax=%d,cnt=%d,pj=%6.2fn,max,cnt,pj);fprintf(fw,%dn%dn%6.2fn,max,cnt,pj);fclose(fw);*题目93(方差运算题)请编制函数readdat()实现从文件in.dat中读取1000个十进制整数到数组xx中;请编制函数compute(),分别计算出xx中奇数的个数odd,偶数的个数even,平均值aver以及方差totfc的值,最后调用函数writedat()把结果输出到out.dat
6、文件中。 计算方差的公式如下: n 2 totfc=1/n (xxi-aver) i=1原始数据文件存放的格式是:每行存放10个数,并用逗号隔开。(每个数均大于0且小于等于2000)部分源程序存在文件prog1.c中。请勿改动主函数main()和输出数据函数writedat()的内容。#include #include #include #define max 1000int xxmax,odd=0,even=0;double aver=0.0,totfc=0.0;void writedat(void);int readdat(void)int i;file *fp;if(fp=fopen(i
7、n.dat,r)=null) return 1;/*编制函数readdat()*/for(i=0;imax;i+) fscanf(fp,%d,&xxi); if(i+1)%10=0) fscanf(fp,n);/*/fclose(fp);return 0;void compute(void) int i;for(i=0;imax;i+) if(xxi%2) odd+; else even+; aver+=xxi; aver/=max;for(i=0;imax;i+) totfc+=(xxi-aver)*(xxi-aver);totfc/=max;void main()int i;for(i=0
8、;imax;i+)xxi=0;if(readdat() printf(数据文件in.dat不能打开!007n); return;compute();printf(odd=%dnoven=%dnaver=%fntotfc=%fn,odd,even,aver,totfc);writedat();void writedat(void)file *fp;int i;fp=fopen(out.dat,w);fprintf(fp,%dn%dn%fn%fn,odd,even,aver,totfc);fclose(fp);*题目94(整数统计运算题)请编制程序prog1.c,从文件in.dat中读取200个整
9、数至数组xx中,求出奇数的个数cnt1和偶数的个数cnt2以及数组xx中值为偶数的算术平均值pj(保留2位小数)。结果cnt1,cnt2,pj输出到out.dat中。部分程序、读数据函数read_dat(int xx200)及输出格式已给出。#include #include #define n 200void read_dat(int xxn)int i,j;file *fp;fp=fopen(in.dat,r);for(i=0;i20;i+) for(j=0;j10;j+) fscanf(fp,%d,&xxi*10+j); printf(%d ,xxi*10+j);printf(n);fc
10、lose(fp);void main()int m,sum;int cnt1,cnt2,xxn;float pj;file *fw;fw=fopen(out.dat,w);clrscr();read_dat(xx);/*/cnt1=0; cnt2=0; pj=0.0;for(m=0;mn;m+) if(xxm%2) cnt1+; else cnt2+; pj+=xxm;if(cnt2=0) pj=0;else pj/=cnt2;/*/printf(nncnt1=%d,cnt2=%d,pj=%6.2fn,cnt1,cnt2,pj);fprintf(fw,%dn%dn%6.2fn,cnt1,cnt
11、2,pj);fclose(fw);*题目95(字符替换题)函数readdat()实现从文件eng.in中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptchar(),按给定的替代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数writedat()把结果xx输出到文件ps4.da中。替代关系:f(p)=p*11 mod 256(p是数组中某一个字符的ascii值,f(p)是计算后新字符的ascii值),如果计算后f(p)值小于等于32或f(p)对应的字符是大写字母,则该字符不变,否则将f(p)所对应的字符进行替代。部分源程序存在文件prog1.c中
12、。原始数据文件存放的格式是:每行的宽度均小于80个字符。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。#include #include #include #include unsigned char xx5080;int maxline=0;/*文章的总行数*/int readdat(void);void writedat(void);void encryptchar() int i,j;for(i=0;imaxline;i+) for(j=0;jstrlen(xxi);j+) if(xxij*11%256=a&xxij*11%256=z)
13、 continue; else xxij=xxij*11%256;void main()clrscr();if(readdat()printf(数据文件eng.in不能打开!n007);return;encryptchar();writedat();int readdat(void)file *fp;int i=0;unsigned char *p;if(fp=fopen(eng.in,r)=null) return 1;while(fgets(xxi,80,fp)!=null) p=strchr(xxi,n); if(p)*p=0; i+;maxline=i;fclose(fp);retur
14、n 0;void writedat(void)file *fp;int i;fp=fopen(ps4.dat,w);for(i=0;imaxline;i+)printf(%sn,xxi);fprintf(fp,%sn,xxi);fclose(fp);题目96(字符替换题)函数readdat()实现从文件eng.in中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptchar(),按给定的替代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数writedat()把结果xx输出到文件ps5.dat中。替代关系:f(p)=p*11mod 256 (p是数组
15、中某一个字符的ascii值,f(p)是计算后新字符的ascii值),如果原字符是小写字母或计算后f(p)值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。部分源程序存在文件prog1.c中。原始数据文件存放的格式是:每行的宽度均小于80个字符。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。#include #include #include #include unsigned char xx5080;int maxline=0;/*文章的总行数*/int readdat(void);void writedat(void);vo
16、id encryptchar() int i,j;for(i=0;imaxline;i+) for(j=0;jstrlen(xxi);j+) if(xxij*11%256=a&xxij=z) continue; else xxij=xxij*11%256;void main()clrscr();if(readdat()printf(数据文件eng.in不能打开!n007);return;encryptchar();writedat();int readdat(void)file *fp;int i=0;unsigned char *p;if(fp=fopen(eng.in,r)=null) r
17、eturn 1;while(fgets(xxi,80,fp)!=null) p=strchr(xxi,n); if(p)*p=0; i+;maxline=i;fclose(fp);return 0;void writedat(void)file *fp;int i;fp=fopen(ps5.dat,w);for(i=0;imaxline;i+)printf(%sn,xxi);fprintf(fp,%sn,xxi);fclose(fp);*题目97(字符替换题)函数readdat()实现从文件eng.in中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptchar(),按给定的替
18、代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数writedat()把结果xx输出到文件ps9.dat中。替代关系:f(p)=p*11 mod 256(p是数组中某一个字符的ascii值,f(p)是计算后新字符的ascii值),如果原字符是数字字符0至9或计算后f(p)值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。部分源程序存在文件prog1.c中。原始数据文件存放的格式是:每行的宽度均小于80个字符。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。#include #include #inc
19、lude #include unsigned char xx5080;int maxline=0;/*文章的总行数*/int readdat(void);void writedat(void);void encryptchar() int i,j;for(i=0;imaxline;i+) for(j=0;jstrlen(xxi);j+) if(xxij*11%256=0&xxij=9) continue; else xxij=xxij*11%256;void main()clrscr();if(readdat()printf(数据文件eng.in不能打开!n007);return;encryp
20、tchar();writedat();int readdat(void)file *fp;int i=0;unsigned char *p;if(fp=fopen(eng.in,r)=null) return 1;while(fgets(xxi,80,fp)!=null) p=strchr(xxi,n); if(p)*p=0; i+;maxline=i;fclose(fp);return 0;void writedat(void)file *fp;int i;fp=fopen(ps9.dat,w);for(i=0;imaxline;i+)printf(%sn,xxi);fprintf(fp,%
21、sn,xxi);fclose(fp);*题目98(字符替题) 函数readdat()实现从文件eng.in中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptchar(),按给定的替代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数writedat()把结果xx输出到文件ps3.dat中。替代关系:f(p)=p*17 mod 256(p是数组中某一个字符的ascii值,f(p)是计算后新字符的ascii值),如果计算后f(p)值小于等于32或其ascii值是奇数,则该字符不变,否则将f(p)所对应的字符进行替代。部分源程序存在文件prog1.c中。
22、原始数据文件存放的格式是:每行的宽度均小于80个字符。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。#include #include #include #include unsigned char xx5080;int maxline=0;/*文章的总行数*/int readdat(void);void writedat(void);void encryptchar() int i,j;for(i=0;imaxline;i+) for(j=0;jstrlen(xxi);j+) if(xxij*17%256=32|(xxij*17%256)%
23、2!=0) continue; else xxij=xxij*17%256;void main()clrscr();if(readdat()printf(数据文件eng.in不能打开!n007);return;encryptchar();writedat();int readdat(void)file *fp;int i=0;unsigned char *p;if(fp=fopen(eng.in,r)=null) return 1;while(fgets(xxi,80,fp)!=null) p=strchr(xxi,n); if(p)*p=0; i+;maxline=i;fclose(fp);
24、return 0;void writedat(void)file *fp;int i;fp=fopen(ps3.dat,w);for(i=0;imaxline;i+)printf(%sn,xxi);fprintf(fp,%sn,xxi);fclose(fp);*题目99(结构体排列题)已知在文件in.dat中存有100个产品销售记录,每个产品销售记录由产品代码dm(字符型4位),产品名称mc(字符型10位),单价dj(整型),数量sl(整型),金额je(长整型)五部分组成。其中:金额=单价*数量计算得出。函数readdat()是读取这100个销售记录并存入结构数组sell中。请编制函数sort
25、dat(),其功能要求:按金额从小到大进行排列,若金额相等,则按产品代码从小到大进行排列,最终排列结果仍存入结构数组sell中,最后调用函数writedat()把结果输出到文件out1.dat中。部分源程序存在文件prog1.c中。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。#include #include #include #include #include #define max 100typedef structchar dm5; /*产品代码*/char mc11; /*产品名称*/int dj; /*单价*/int sl; /*
26、数量*/long je; /*金额*/pro;pro sellmax;void readdat();void writedat();void sortdat()int i,j;pro xy;for(i=0;i99;i+)for(j=i+1;jsellj.je|selli.je=sellj.je&strcmp(selli.dm,sellj.dm)0) xy=selli;sell i=sellj;sellj=xy;void main()memset(sell,0,sizeof(sell);readdat();sortdat();writedat();void readdat()file *fp;c
27、har str80,ch11;int i;fp=fopen(in.dat,r);for(i=0;i100;i+) fgets(str,80,fp); memcpy(selli.dm,str,4); memcpy(selli.mc,str+4,10); memcpy(ch,str+14,4);ch4=0; selli.dj=atoi(ch); memcpy(ch,str+18,5);ch5=0; selli.sl=atoi(ch); selli.je=(long)selli.dj*selli.sl;fclose(fp);void writedat()file *fp;int i;fp=fopen(out1.dat,w);for(i=0;i100;i+)printf(%s %s %4d %5d %5dn, selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fprintf(fp,%s %s %4d %5d %5dn, selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fclose(fp);*题目100(字符替换题)函数readdat()实现从文件in.dat中读取一篇英文文章存入到字符串数组x
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025股权转让合同专业版(合同版本)
- 2025年小学英语毕业考试口语模拟试卷(口语表达训练方法)
- 《红小豆中的活性成分对人体生理功能的调节》论文
- 2025租赁合同模板范文
- 护士白内障护理查房
- 2025-2030绕嵌线机市场发展分析及行业投资战略研究报告
- 2025-2030纸箱行业风险投资态势及投融资策略指引报告
- 2025-2030素食蛋黄酱行业市场现状供需分析及投资评估规划分析研究报告
- 2025-2030等离子喷涂材料行业市场深度调研及前景趋势与投资研究报告
- 2025-2030穿刺活检器械行业供需平衡分析及发展前景研究报告
- 缝纫培训课件
- 总裁助理岗位职责
- 中建落地式脚手架施工方案
- 《中华人民共和国机动车驾驶人科目一考试题库》
- 倪海厦天纪学习笔记以及讲义
- 租号协议书合同范本
- 医疗安全不良事件报告制度培训
- 抗菌药物的合理应用培训
- 操场跑道废旧处理方案
- 高效能人士的七个习惯(课件)
- 2023年新课标全国Ⅰ卷数学真题(解析版)
评论
0/150
提交评论