C语言实验报告,实验7

上传人:飞*** 文档编号:44256212 上传时间:2018-06-09 格式:DOC 页数:7 大小:209.50KB
返回 下载 相关 举报
C语言实验报告,实验7_第1页
第1页 / 共7页
C语言实验报告,实验7_第2页
第2页 / 共7页
C语言实验报告,实验7_第3页
第3页 / 共7页
C语言实验报告,实验7_第4页
第4页 / 共7页
C语言实验报告,实验7_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《C语言实验报告,实验7》由会员分享,可在线阅读,更多相关《C语言实验报告,实验7(7页珍藏版)》请在金锄头文库上搜索。

1、本科实验报告本科实验报告课程名称: C 语言程序设计 实验项目: 实验七、八、九、十 实验地点: 中区 ZSA303 专业班级: 软件 11 学号:201100 学生姓名: 指导教师: 2011 年 06 月 01 日实验七实验七 指指 针针1.输入有一行字符,将字符串中的字符逆序后输出。#include#include #include#include voidvoid main()main() charchar s8,*p=s;s8,*p=s; printf(“input:n“);printf(“input:n“); gets(s);gets(s); p p = = s s + + str

2、len(s)strlen(s) - - 1;1; if(*p!=0)if(*p!=0) p+;p+; for(;p=s;p-)for(;p=s;p-) printf(“%c“,*p);printf(“%c“,*p); printf(“n“);printf(“n“); 2.输入有一行字符,编程序将每个单词的第一个字母改为大写。#include void main() char a255,*s= printf(“input a strings:“); scanf(“%n“,s); if (*s=a) *s-=32; while(*(+s) if (*(s-1)= s= printf(“%sn“,s

3、); 实验八实验八 函函 数数1. 编写一个计算 n!的函数,用主函数调用它,使之输出 7 阶杨辉三角形. #include#include #define#define N N 9 9 voidvoid yanghui()yanghui() intint i,j,aNN=0;i,j,aNN=0; for(i=1;i#include intint fun(floatfun(float *score,int*score,int n);n); voidvoid main()main() floatfloat score50;score50; intint i;i; for(i=0;imean)if

4、(scoreimean) num+;num+;运行结果:returnreturn num;num; 实验九实验九 结构体和公用体结构体和公用体1有 5 个学生,每个学生的数据包括学号、姓名、三门课的成绩。从键盘输入这 5 个 学生的数据,要求输出三门课总平均成绩,以及最高分的学生的所有数据。 要求用一个 input 函数输入 5 个学生的数据;用一个 average 函数求总平均成绩;用 max 函数找出最高分的学生;总平均成绩和最高分的学生的所有数据在主函数中输出。#include#include #define#define maxmax 5/*5/*设定要输入成绩的学生个数设定要输入成绩

5、的学生个数*/*/ doubledouble zpj;zpj; /*/*总平均值总平均值*/*/ structstruct studentstudent /*/*结构体结构体*/*/ intint num;num;charchar name10;name10;intint score1;score1;intint score2;score2;intint score3;score3;doubledouble pj;pj;structstruct studentstudent stumax,temp;stumax,temp;voidvoid Input()Input() /*/*输入函数输入函数

6、*/*/ intint i;i; for(i=0;imax;i+)for(i=0;imax;i+)printf(“enterprintf(“enter number“);number“); scanf(“%d“,scanf(“%d“, printf(“enterprintf(“enter name“);name“); scanf(“%s“,scanf(“%s“,printf(“enterprintf(“enter score1“);score1“); scanf(“%d“,scanf(“%d“, printf(“enterprintf(“enter score2“);score2“); sca

7、nf(“%d“,scanf(“%d“, printf(“enterprintf(“enter score3“);score3“); scanf(“%d“,scanf(“%d“, average()average() /*/*求平均值函数求平均值函数*/*/ intint i;i; for(i=0;i5;i+)for(i=0;i5;i+) stui.pj=stui.score1+stui.score1+stui.score3;stui.pj=stui.score1+stui.score1+stui.score3; zpj+=stui.pj;zpj+=stui.pj;运行结果: for(i=0;i

8、5;i+)for(i=0;i5;i+)stui.pj/=3;stui.pj/=3;zpj/=max;zpj/=max; MAX()MAX() /*/*找出最高平均值的学生的函数找出最高平均值的学生的函数*/*/ intint i,j;i,j;temp=stu0;temp=stu0;for(i=0;imax-1;i+)for(i=0;imax-1;i+)for(j=i+1;jmax;j+)for(j=i+1;jmax;j+)if(stui.pjstuj.pj)if(stui.pjstuj.pj)temp=stuj;temp=stuj; output()output() /*/*输出函数输出函数*

9、/*/ intint i;i;for(i=0;imax;i+)for(i=0;imax;i+)printf(“num=%dnprintf(“num=%dn name=%snname=%sn score1=%dnscore1=%dn score2=%dnscore2=%dn score3=%dnscore3=%dn aver=%fn“,aver=%fn“,stui.num,stui.name,stui.score1,stui.score2,stui.score3,stui.pj);stui.num,stui.name,stui.score1,stui.score2,stui.score3,stu

10、i.pj);printf(“printf(“总平均分总平均分=%fnn“,zpj);=%fnn“,zpj); printf(“printf(“平均分最高的学生平均分最高的学生nnum=%dnnnum=%dn name=%snname=%sn score1=%dnscore1=%dn score2=%dnscore2=%dn score3=%dnscore3=%dn aver=%fn“,aver=%fn“,temp.num,temp.name,temp.score1,temp.score2,temp.score3,temp.pj);temp.num,temp.name,temp.score1,t

11、emp.score2,temp.score3,temp.pj); voidvoid main()main() /*/*主函数主函数*/*/ Input();Input();average();average();MAX();MAX();output();output(); 实验十实验十 文文 件件1.有 5 个学生,每个学生有 3 门课的成绩,从键盘输入以上数据(包括学生号,姓名, 三门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件 “stud”中。 2.将上题“stud”文件中的学生数据,按平均分进行排序处理,将已排序的学生数据 存入一个新文件“stu_sort”中。#

12、include“stdio.h“#include“stdio.h“ #include“stdlib.h“#include“stdlib.h“ #define#define M M 5 5#define#define stustu structstruct studentstudent stustu intint num;num; charchar name20;name20; floatfloat s1;s1; floatfloat s2;s2; floatfloat s3;s3; floatfloat avg;avg; ; main()main() stustu stM,temp;stM,t

13、emp; FILEFILE *fp,*fp1;*fp,*fp1; intint i,j;i,j; for(i=0;iM;i+)for(i=0;iM;i+) scanf(“%d%s%f%f%f“,scanf(“%d%s%f%f%f“, sti.avg=(sti.s1+sti.s2+sti.s3)/3;sti.avg=(sti.s1+sti.s2+sti.s3)/3; if(fp=fopen(“stud“,“wb“)=NULL)if(fp=fopen(“stud“,“wb“)=NULL) printf(“cannotprintf(“cannot openopen filen“);filen“);

14、for(i=0;iM;i+)for(i=0;iM;i+) if(fwrite(errorn“); fclose(fp);fclose(fp); fp=fopen(“stud“,“rb“);fp=fopen(“stud“,“rb“); printf(“numtnametscore1tscore2tscore3taveragen“);printf(“numtnametscore1tscore2tscore3taveragen“); for(i=0;iM;i+)for(i=0;iM;i+) fread(fread( printf(“%dt%st%ft%ft%ft%fn“,sti.num,printf(“%dt%st%ft%ft%ft%fn“,sti.num, sti.name,sti.s1,sti.s2,sti.s3,sti.avg);sti.name,sti.s1,sti.s2,sti.s3,sti.avg); prin

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号