1、i+) days+=ai; days+=d; struct date int 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);%d年%d月%d日是该年的第%d天n,a.year,a.month,a.day,a.days);*/*#define N 10 /第3、4题时N为5,第5题时N为10struct student int num; char name2
2、0; float score3; float ave; /第3、4、5题共用一个结构体类型stuN;void print(struct student a) int i;学号 姓名t三门课成绩n for(i=0;N; printf(%ld %st%-5.1f %-5.1f %-5.1fn,ai.num,ai.name,ai.score0,ai.score1,ai.score2);请输入%d个学生的信息:学号、姓名、三门课成绩:n,N); scanf(%d %s %f %f %fstui.num,&stui.name,&stui.score0,&stui.score1,&stui.score2)
3、; print(stu);void input(struct student a) /在上一题的基础上编写input函数 input(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 i,m=0; float average=0; stui.av
4、e=(stui.score0+stui.score1+stui.score2)/3; average+=stui.ave/N; for(i=1; if(stui.avestum.ave) m=i;三门课程总平均成绩为:%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 a /原来的序号 int count; /报数数目 str
5、uct a *next; int i,j=1; struct a *p1,*p2,bN; p1=b; bi.num=i+1; /定义序号为1到13 if(i=N-1) bi.next=&b0; /将最后一个节点的指针变量指向第一个节点 elsebi+1; /将每个节点的指针变量指向下一个节点 while(p1-next!=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成员,使
6、之指向下一个报数为1的/成员; j+=1; p1=p1- /p1指向下一个count不为3的成员最后留在圈子的人原来的序号为:%dn,p1-num);# define L sizeof(struct student) long 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);%ld,%fp1-num,&score); head=NULL;n
7、um!=0) n+=1; if(n=1)head=p1; else p2-next=p1; p2=p1; p1=malloc(L); p2-next=NULL; return head;void print(struct student *head) /输出链表的函数 struct student *p=head;nnow,these records are: while(p!=NULL)%ld %5.1fn,p-num,p- p=p-struct student *del1(struct student *head,long num) /删除指定节点的函数,方法一,指定删除节点的数据 p1=head; if(p1-num=num) return head=p1- while(p1-=num) p2- return head;struct student *del2(struct student *head,int n) /方法二,指定删除节点序号 int i=1; if(i=n) while(i+ /int n; head=creat(); print(head);n输入要删除学生的学号: /printf(n输入要删除节点序号:%ld /scanf(%dn); head=del1(head,num); /head=del2(head,n);p
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1