资源预览内容
第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
第9页 / 共15页
第10页 / 共15页
亲,该文档总共15页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
#include#include/*int days(int y,int m,int d) /计算天数 int days=0,i;int a12=31,28,31,30,31,30,31,31,30,31,30,31;if(y%4=0&y%100!=0|y%400=0) /判断是否为闰年a1+=1;if(m=1)return days;elsefor(i=0;im-1;i+)days+=ai;days+=d;return days;struct dateint year;int month;int day;int days;a;int main()printf(enter date:);scanf(%d %d %d,&a.year,&a.month,&a.day);a.days=days(a.year,a.month,a.day);printf(%d年%d月%d日是该年的第%d天n,a.year,a.month,a.day,a.days);*/*#define N 10 /第3、4题时N为5,第5题时N为10struct studentint num;char name20;float score3;float ave; /第3、4、5题共用一个结构体类型stuN;*/*void print(struct student a)int i;printf(学号 姓名t三门课成绩n);for(i=0;iN;i+)printf(%ld %st%-5.1f %-5.1f %-5.1fn,ai.num,ai.name,ai.score0,ai.score1,ai.score2);int main()int i;printf(请输入%d个学生的信息:学号、姓名、三门课成绩:n,N);for(i=0;iN;i+)scanf(%d %s %f %f %f,&stui.num,&stui.name,&stui.score0,&stui.score1,&stui.score2);print(stu);*/*void print(struct student a)int i;printf(学号 姓名t三门课成绩n);for(i=0;iN;i+)printf(%ld %st%-5.1f %-5.1f %-5.1fn,ai.num,ai.name,ai.score0,ai.score1,ai.score2);void input(struct student a) /在上一题的基础上编写input函数int i;printf(请输入%d个学生的信息:学号、姓名、三门课成绩:n,N);for(i=0;iN;i+)scanf(%d %s %f %f %f,&stui.num,&stui.name,&stui.score0,&stui.score1,&stui.score2);int main()input(stu);print(stu);*/ /*测试数据10101 wu 70 71 9010102 chen 60 64 9010103 guo 80 78 9010104 lu 80 64 9010105 xu 60 65 9010106 huang 90 78 9010107 chen 70 66 9010108 rong 90 72 9010109 yang 50 63 9010110 zhang 50 71 90*/*int main()int i,m=0;float average=0;printf(请输入%d个学生的信息:学号、姓名、三门课成绩:n,N);for(i=0;iN;i+)scanf(%d %s %f %f %f,&stui.num,&stui.name,&stui.score0,&stui.score1,&stui.score2);stui.ave=(stui.score0+stui.score1+stui.score2)/3;average+=stui.ave/N;for(i=1;istum.ave)m=i;printf(三门课程总平均成绩为:%5.1fn成绩最高的学生是:n学号:%dn姓名:%sn三门课成绩:%5.1f,%5.1f,%5.1fn平均成绩:%6.2fn,average,stum.num,stum.name,stum.score0,stum.score1,stum.score2,stum.ave);*/*#define N 13 /定义人数struct aint num; /原来的序号int count; /报数数目struct a *next;int main()int i,j=1;struct a *p1,*p2,bN;p1=b;for(i=0;inext!=p1) /p1的next成员指向自己时表明只剩最后一个人p1-count=j; /报数if(j=2)p2=p1; /p2的作用是标记报数为2的人if(j=3)j=1;p2-next=p1-next; /将报数为3的next成员赋值给上一个报数为2的next成员,使之指向下一个报数为1的/成员;elsej+=1;p1=p1-next; /p1指向下一个count不为3的成员printf(最后留在圈子的人原来的序号为:%dn,p1-num);*/*# define L sizeof(struct student)struct studentlong num;float score;struct student *next;int n;struct student *creat(void) /生成单向动态链表的函数 struct student *head;struct student *p1,*p2;n=0;p1=p2=malloc(L);scanf(%ld,%f,&p1-num,&p1-score);head=NULL;while(p1-num!=0)n+=1;if(n=1)head=p1;else p2-next=p1;p2=p1;p1=malloc(L);scanf(%ld,%f,&p1-num,&p1-score);p2-next=NULL;return head;void print(struct student *head) /输出链表的函数struct student *p=head;printf(nnow,these records are:n);while(p!=NULL)printf(%ld %5.1fn,p-num,p-score);p=p-next;struct student *del1(struct student *head,long num) /删除指定节点的函数,方法一,指定删除节点的数据struct student *p1,*p2;p1=head;if(p1-num=num)return head=p1-next;elsewhile(p1-num!=num) p2=p1; p1=p1-next; p2-next=p1-next; p1-next=NULL;return head;struct student *del2(struct student *head,int n) /方法二,指定删除节点序号struct student *p1,*p2;int i=1;p1=head;if(i=n)return head=p1-next;else while(i+next;p2-next=p1-next; p1-next=NULL;return head;int main()struct student *head;long num; /int n;head=creat();print(head);printf(n输入要删除学生的学号:); /printf(n输入要删除节点序号:);scanf(%ld,&num); /scanf(%d,&n);head=del1(head,num); /head=del2(head,n); print(head);*/*# define L sizeof(struct stude
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号