c程序设计第四版谭浩强第九章答案Word格式文档下载.docx

上传人:b****5 文档编号:15749213 上传时间:2022-11-15 格式:DOCX 页数:21 大小:18.86KB
下载 相关 举报
c程序设计第四版谭浩强第九章答案Word格式文档下载.docx_第1页
第1页 / 共21页
c程序设计第四版谭浩强第九章答案Word格式文档下载.docx_第2页
第2页 / 共21页
c程序设计第四版谭浩强第九章答案Word格式文档下载.docx_第3页
第3页 / 共21页
c程序设计第四版谭浩强第九章答案Word格式文档下载.docx_第4页
第4页 / 共21页
c程序设计第四版谭浩强第九章答案Word格式文档下载.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

c程序设计第四版谭浩强第九章答案Word格式文档下载.docx

《c程序设计第四版谭浩强第九章答案Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《c程序设计第四版谭浩强第九章答案Word格式文档下载.docx(21页珍藏版)》请在冰豆网上搜索。

c程序设计第四版谭浩强第九章答案Word格式文档下载.docx

i++)

days+=a[i];

days+=d;

}

}

structdate

intyear;

intmonth;

intday;

intdays;

}a;

intmain()

printf("

enterdate:

"

);

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);

*/

/*#defineN10//第3、4题时N为5,第5题时N为10

structstudent

intnum;

charname[20];

floatscore[3];

floatave;

//第3、4、5题共用一个结构体类型

}stu[N];

voidprint(structstudenta[])

inti;

学号姓名\t三门课成绩\n"

for(i=0;

N;

printf("

%ld%s\t%-5.1f%-5.1f%-5.1f\n"

a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);

请输入%d个学生的信息:

学号、姓名、三门课成绩:

\n"

N);

scanf("

%d%s%f%f%f"

stu[i].num,&

stu[i].name,&

stu[i].score[0],&

stu[i].score[1],&

stu[i].score[2]);

print(stu);

voidinput(structstudenta[])//在上一题的基础上编写input函数

input(stu);

*/

测试数据

10101wu707190

10102chen606490

10103guo807890

10104lu806490

10105xu606590

10106huang907890

10107chen706690

10108rong907290

10109yang506390

10110zhang507190

inti,m=0;

floataverage=0;

stu[i].ave=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;

average+=stu[i].ave/N;

for(i=1;

if(stu[i].ave>

stu[m].ave)

m=i;

三门课程总平均成绩为:

%5.1f\n成绩最高的学生是:

\n学号:

%d\n姓名:

%s\n三门课成绩:

%5.1f,%5.1f,%5.1f\n平均成绩:

%6.2f\n"

average,stu[m].num,stu[m].name,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].ave);

#defineN13//定义人数

structa

//原来的序号

intcount;

//报数数目

structa*next;

};

inti,j=1;

structa*p1,*p2,b[N];

p1=b;

b[i].num=i+1;

//定义序号为1到13

if(i==N-1)

b[i].next=&

b[0];

//将最后一个节点的指针变量指向第一个节点

else

b[i+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成员,使之指向下一个报数为1的//成员;

}

j+=1;

p1=p1->

//p1指向下一个count不为3的成员

最后留在圈子的人原来的序号为:

%d\n"

p1->

num);

#defineLsizeof(structstudent)

longnum;

floatscore;

structstudent*next;

intn;

structstudent*creat(void)//生成单向动态链表的函数

structstudent*head;

structstudent*p1,*p2;

n=0;

p1=p2=malloc(L);

%ld,%f"

p1->

num,&

score);

head=NULL;

num!

=0)

n+=1;

if(n==1)head=p1;

elsep2->

next=p1;

p2=p1;

p1=malloc(L);

p2->

next=NULL;

returnhead;

voidprint(structstudent*head)//输出链表的函数

structstudent*p=head;

\nnow,theserecordsare:

while(p!

=NULL)

%ld%5.1f\n"

p->

num,p->

p=p->

structstudent*del1(structstudent*head,longnum)//删除指定节点的函数,方法一,指定删除节点的数据

p1=head;

if(p1->

num==num)

returnhead=p1->

while(p1->

=num)

p2->

returnhead;

structstudent*del2(structstudent*head,intn)//方法二,指定删除节点序号

inti=1;

if(i==n)

while(i++<

n)

p1=p1->

//intn;

head=creat();

print(head);

\n输入要删除学生的学号:

//printf("

\n输入要删除节点序号:

%ld"

//scanf("

%d"

n);

head=del1(head,num);

//head=del2(head,n);

p

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1