c程序设计第四版谭浩强第九章答案.docx

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

c程序设计第四版谭浩强第九章答案.docx

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

c程序设计第四版谭浩强第九章答案.docx

c程序设计第四版谭浩强第九章答案

#include

#include

/*

intdays(inty,intm,intd)//计算天数

{

intdays=0,i;

inta[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if(y%4==0&&y%100!

=0||y%400==0)//判断是否为闰年

a[1]+=1;

if(m==1)

returndays;

else

{

for(i=0;i

days+=a[i];

days+=d;

returndays;

}

}

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

printf("%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;

printf("学号姓名\t三门课成绩\n");

for(i=0;i

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

}

intmain()

{

inti;

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

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

\n",N);

for(i=0;i

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

}

*/

/*

voidprint(structstudenta[])

{

inti;

printf("学号姓名\t三门课成绩\n");

for(i=0;i

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

}

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

{

inti;

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

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

\n",N);

for(i=0;i

scanf("%d%s%f%f%f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

}

intmain()

{

input(stu);

print(stu);

}

*/

/*

测试数据

10101wu707190

10102chen606490

10103guo807890

10104lu806490

10105xu606590

10106huang907890

10107chen706690

10108rong907290

10109yang506390

10110zhang507190

*/

/*

intmain()

{

inti,m=0;

floataverage=0;

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

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

\n",N);

for(i=0;i

{

scanf("%d%s%f%f%f",&stu[i].num,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

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

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

}

for(i=1;i

if(stu[i].ave>stu[m].ave)

m=i;

printf("三门课程总平均成绩为:

%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

{

intnum;//原来的序号

intcount;//报数数目

structa*next;

};

intmain()

{

inti,j=1;

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

p1=b;

for(i=0;i

{

b[i].num=i+1;//定义序号为1到13

if(i==N-1)

b[i].next=&b[0];//将最后一个节点的指针变量指向第一个节点

else

b[i].next=&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的//成员;

}

else

j+=1;

p1=p1->next;//p1指向下一个count不为3的成员

}

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

%d\n",p1->num);

}

*/

/*

#defineLsizeof(structstudent)

structstudent

{

longnum;

floatscore;

structstudent*next;

};

intn;

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

{

structstudent*head;

structstudent*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;

elsep2->next=p1;

p2=p1;

p1=malloc(L);

scanf("%ld,%f",&p1->num,&p1->score);

}

p2->next=NULL;

returnhead;

}

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

{

structstudent*p=head;

printf("\nnow,theserecordsare:

\n");

while(p!

=NULL)

{

printf("%ld%5.1f\n",p->num,p->score);

p=p->next;

}

}

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

{

structstudent*p1,*p2;

p1=head;

if(p1->num==num)

returnhead=p1->next;

else

{

while(p1->num!

=num)

{

p2=p1;

p1=p1->next;

}

p2->next=p1->next;

p1->next=NULL;

returnhead;

}

}

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

{

structstudent*p1,*p2;

inti=1;

p1=head;

if(i==n)

returnhead=p1->next;

else

{

while(i++

{

p2=p1;

p1=p1->next;

}

p2->next=p1->next;

p1->next=NULL;

returnhead;

}

}

intmain()

{

structstudent*head;

longnum;//intn;

head=creat();

print(head);

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

");//printf("\n输入要删除节点序号:

");

scanf("%ld",&num);//scanf("%d",&n);

head=del1(head,num);//head=del2(head,n);

print(head);

}

*/

/*

#defineLsizeof(structstudent)

structstudent

{

longnum;

floatscore;

structstudent*next;

};

intn;

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

{

structstudent*head;

structstudent*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;

elsep2->next=p1;

p2=p1;

p1=malloc(L);

scanf("%ld,%f",&p1->num,&p

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

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

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

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