




已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件stud中。1.程序分析:2.程序源代码:#include stdio.hstruct student char num6;char name8;int score3;float avr; stu5;main()int i,j,sum;FILE *fp;/*input*/for(i=0;i5;i+) printf(n please input No. %d score:n,i);printf(stuNo:);scanf(%s,stui.num);printf(name:);scanf(%s,);sum=0;for(j=0;j3;j+) printf(score %d.,j+1);scanf(%d,&stui.scorej);sum+=stui.scorej;stui.avr=sum/3.0;fp=fopen(stud,w);for(i=0;i5;i+)if(fwrite(&stui,sizeof(struct student),1,fp)!=1)printf(file write errorn);fclose(fp);题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件C中。1.程序分析:2.程序源代码:#include stdio.hmain() FILE *fp;int i,j,n,ni;char c160,t,ch;if(fp=fopen(A,r)=NULL)printf(file A cannot be openedn);exit(0);printf(n A contents are :n);for(i=0;(ch=fgetc(fp)!=EOF;i+)ci=ch;putchar(ci);fclose(fp);考试大全国最大教育类网站(wwwE)ni=i;if(fp=fopen(B,r)=NULL)printf(file B cannot be openedn);exit(0);printf(n B contents are :n);for(i=0;(ch=fgetc(fp)!=EOF;i+)ci=ch;putchar(ci);fclose(fp);n=i;for(i=0;in;i+)for(j=i+1;jcj)t=ci;ci=cj;cj=t;printf(n C file is:n);fp=fopen(C,w);for(i=0;i=a&strii)printf(please input a little smaller.n);scanf(%d,&guess);elseprintf(please input a little bigger.n);scanf(%d,&guess);end=clock();b=time(NULL);printf(1: It took you %6.3f secondsn,var=(double)(end-start)/18.2);printf(1: it took you %6.3f secondsnn,difftime(b,a);if(var15)printf(11 You are very clever! 11nn);else if(var25)printf(11 you are normal! 11nn);elseprintf(11 you are stupid! 11nn);printf(11 Congradulations 11nn);printf(The number you guess is %d,i);printf(ndo you want to try it again?(yy.or.n)n);if(c=getch()=y)goto loop;题目:时间函数举例31.程序分析:2.程序源代码:/*calculate time*/#include time.h#include stdio.hmain() clock_t start,end;int i;double var;start=clock();for(i=0;i10000;i+) printf(1111111111n);end=clock();printf(1: The different is %6.3fn,(double)(end-start);来源:考试大-计算机二级考试 题目:通讯录#include #include #include /* 定义保存通迅录的信息 */ struct friends char name20; /* 名字 */ char province20; /* 省份 */ char city20; /* 所在城市 */ char nation20; /* 民族 */ char sex2; /* 性别 M/F */ int age; /* 年龄 */ ; void getname (char search_name); int search (struct friends friend_list, char search_name); void print_result(struct friends friend_list, int index); int main (void) int index; char search_name20; struct friends friend_list4 = lihan, liaoning, huluodao,han,M,19, zhuqiang, jiangsu, changzhu, han,M,19, wangjiangang, liaoning, anshan,han,M,20, zhanghongwei, shandong, zhucheng, han,M,21, ; (void) getname (search_name); /* 获得用户输入 */ index = search (friend_list, search_name); /* 查询 */ (void) print_result (friend_list,index); /* 打印结果 */ return 0; /* * 函数名:getname * 功能:获得用户要查询的对象的名字 */ void getname (char search_name) printf (Pleace enter the name of your friends you want to search); scanf (%s, search_name); /* * 函数名:search * 功能:查询对象 */ int search (struct friends friend_list, char search_name) int i; /* 穷举通迅录 */ for (i = 0; i 4; +i) if (strcmp(friend_, search_name) = 0) return (i); if (i = 4) printf (I am sorry! there is nobody by the name you enter!n); fflush(stdin); getchar(); exit (0); /* * 函数名:print_result * 功能:打印结果 */ void print_result(struct friends friend_list, int index) printf (the imformation of %s:n, friend_); printf (-n); printf ( NAME: %-sn, friend_); printf (PROVINCE: %-sn, friend_vince); printf ( CITY: %-sn, friend_listindex.ci
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 自然语言及语音处理项目式教程 实训指导 实训1 配置NLP环境
- 分析师预期选股策略月报:分析师预期修正选股策略今年相对中证全指超额3.06
- 2025以色列与伊朗冲突全面解析课件
- 氢能源未来2025年加氢站建设成本效益分析与布局指南报告
- 2025年家具制造业个性化定制生产模式市场风险预警报告
- 2025年煤炭清洁燃烧技术产业链上下游协同发展报告
- 工业互联网平台安全多方计算在智能仓储物流中的应用报告
- 教育大数据分析2025年:教育资源配置优化与教育公平研究报告
- 工业互联网平台网络安全态势感知技术在电力行业的应用与优化报告
- 工业互联网平台安全多方计算技术:2025年网络安全风险预警与应对策略研究报告
- 医疗器械经营质量体系文件-质量管理制度
- DB11T 811-2011 场地土壤环境风险评价筛选值
- DB34∕T 1555-2011 存量房交易计税价格评估技术规范
- 桂科版八年级下册信息技术 1.1规划网站 教学设计
- 民办学校托管合同范本
- 风扇合同范本
- GB/T 44325-2024工业循环冷却水零排污技术规范
- 电机噪声与振动分析考核试卷
- 2024年重庆市高考思想政治试卷真题(含答案解析)
- 生产与运作管理第5版配套教材电子课件(完整版)
- 成人鼻肠管的留置与维护(2021团体标准解读)-20221004172843
评论
0/150
提交评论