资源描述:
《第8章 习题参考答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《C语言程序设计》习题参考答案第8章习题参考答案1.判断题:123456√×××√√2.选择题12345678DDDCDADD3.程序阅读(1)2,4,6,8,10,。(2)10987654321(3)Shen。(4)18。(5)484.程序填空(1)p->next!=NULLp->infop=p->next;(2)p1->next!=NULLp0->next=p1;p0->next=NULL;(3)s[k].avers[k].aver>s[maxsub].avermaxsub=k(4)headn++p->next5.编程题(1)structcomplx{intrea
2、l;intim;};main(){structcomplxc1,c2,c3;scanf("%d+%di",&c1.real,&c1.im);scanf("%d+%di",&c2.real,&c2.im);c3.real=c1.real*c2.real-c1.im*c2.im;c3.im=c1.real*c2.im+c1.im*c2.real;printf("(%d+%di)*(%d+%di)=%d+%di",c1.real,c1.im,c2.real,c2.im,c3.real,c3.im);getch();}(2)#include#include<
3、string.h>main()#defineN10structstudent《C语言程序设计》习题参考答案{longnum;charname[10];floatscore[3];floatave;};main(){voidinput(structstudents[],intn);/*输入n个学生数据*/floataverage(structstudents[],intn);/*计算第n个学生的平均成绩*/intmax(structstudents[],intn);/*计算n个学生中哪个学生的平均成绩最高*/structstudents[N];inti,m;floata
4、=0;/*总平均成绩*/input(s,N);for(i=0;i5、=max(s,N);printf("Themaxscorestudent:");printf("Number:%ldName:%sScore1:%fScore2:%fScore3:%fAverageScore:%f",s[m].num,s[m].name,s[m].score[0],s[m].score[1],s[m].score[2],s[m].ave);}voidinput(structstudents[],intn){inti;for(i=0;i6、canf("%ld",&s[i].num);printf("Pleaseinputstudentname:");scanf("%s",s[i].name);printf("Pleaseinputstudentscore1:");scanf("%f",&s[i].score[0]);printf("Pleaseinputstudentscore2:");《C语言程序设计》习题参考答案scanf("%f",&s[i].score[1]);printf("Pleaseinputstudentscore3:");scanf("%f",&s[i].score[2]);}}flo
7、ataverage(structstudents[],intn){inti;floata=0;for(i=0;i<3;i++)a=a+s[n].score[i];a=a/3;return(a);}intmax(structstudents[],intn){inti,m=0;for(i=1;is[m].ave)m=i;return(m);}(3)structdate{intyear;intmonth;intday;};intdays(structdated){intn,t;if(d.year%4==0&&d.yea