c语言第9章习题参考答案.doc_第1页
c语言第9章习题参考答案.doc_第2页
c语言第9章习题参考答案.doc_第3页
c语言第9章习题参考答案.doc_第4页
c语言第9章习题参考答案.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第9章习题一、选择题12345678910DDACBDCDDB1112131415CDBCA二 填空题1. 成员 指向2. stu 或 struct student311 20 114. printf(“%s”,p-name);5. pp15 struct pp *f();6. (*p).sex or p-sex7. 28. Mary9. r-next=q; p-next=r;10. 32三 程序分析题1. 212. 1999.4 zhang 1999.4 zhang y hang3. 5,34. 1,215. 13四、编程题1. 设计一个通讯录的结构体类型,并画出该结构体变量在内存的存储形式。typedef struct int no; char name15; char gender; char mobile20; char phone20; char address30; Contacts;Contacts con;2. 用结构体变量表示平面上的一个点(横坐标和纵坐标),输入两个点,求两点之间的距离。#include stdio.h#include math.htypedef struct float x; float y; Point;float distance(Point a, Point b) float dis; dis=sqrt(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); return dis;void main() Point a, b; printf(Please input the value of point a(Format: x,y):); scanf(%f,%f, &a.x, &a.y); printf(Please input the value of point b(Format: x,y):); scanf(%f,%f, &b.x, &b.y); printf(The distance between the two points is : %.3f n, distance(a,b);3. 用结构体变量表示日期(年、月、日),任意输入两个日期,求它们之间相差的天数。#include stdio.htypedef struct int year; int month; int day; Date;void main() int month12= 0,31,59,90,120,151,181,212,243,273,304,334, year; Date s, e; long sn, en; printf(Fromat: 2006-6-16-1989-01-25n); scanf(%ld-%ld-%ld-%ld-%ld-%ld, &s.year, &s.month, &s.day, &e.year, &e.month, &e.day); /* 计算起始日期距离公元元年的天数sn */ if( (s.year%4=0 & s.year%100!=0 | s.year%400=0 ) & s.month3 ) year=s.year/4 - s.year/100 + s.year/400 + s.year*365 - 1; else year=s.year/4 - s.year/100 + s.year/400 + s.year*365; sn = months.month - 1 + year + s.day; /* 计算终止日期距离公元元年的天数en */ if( (e.year%4=0 & e.year%100!=0 | e.year%400=0 ) & e.month3 ) year=e.year/4 - e.year/100 + e.year/400 + e.year*365 - 1; else year=e.year/4 - e.year/100 + e.year/400 + e.year*365; en = monthe.month - 1 + year + e.day; printf( There are %ld days between %ld-%ld-%ld and %ld-%ld-%ld.n , sn-en, s.year, s.month, s.day, e.year, e.month, e.day); 4. 用结构体变量表示复数(实部和虚部),输入两个复数,求两复数之积。#includetypedef struct int real; int image; Complex;void main() Complex c1, c2; int real, image; printf(Please input a complex (format: real image)n); scanf(%d%d, &c1.real, &c1.image); printf(Please input another complex (format: real image)n); scanf(%d%d, &c2.real, &c2.image); real=c1.real*c2.real-c1.image*c2.image; image=c1.real*c2.image+c2.real*c1.image; if(image0) printf(multipul result=%d+%din, real, image); else if(image0) printf(multipul result=%d%din, real, image); else printf(multipul result=%dn, real);5有20个学生,每个学生的数据包括学号(num)、姓名(name)、性别(sex)、五门课程成绩(score5)。要求编写一个程序,输入学生数据,计算并输出每个学生的总分和平均分。#include stdio.h#define STU_NUM 3typedef structchar no10;char name15;char sex;float score5; Student;void main()Student stuSTU_NUM;int i, j;float ave=0;/ inputfor(i=0; iSTU_NUM; i+)fflush(stdin);printf(Please input the no of %d student:, i+1);gets(stui.no);printf(Please input the name of %d student:, i+1);gets();printf(Please input the sex of %d student:, i+1);stui.sex=getchar();printf(Please input the five scores of %d student:, i+1);for(j=0; j5; j+)scanf(%f, &stui.scorej);printf(n);/ process and outputfor(i

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论