




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 1、把一个学生的信息 (包括学号、姓名、性别、住址 )放在一个结构体变量中,然后输出这个学生的信息。 #include int main() struct Studelong int numchar name20char sexchar addr20; a=10101, “ Li Lin ” , M , “ 123 Beijing Road ” ; printf(NO.:%ldnname:%sn sex:%cnaddress:%sn,return 0; 2、输入两个学生的学号、姓名和成绩,输出成绩较高学生的学号、姓名和成绩 #include int main() struct Studeni
2、nt nuchar name20float scorstudent1,student2scanf(%d%s%f,&, scanf( “ %d%s%f” ,&, &printf(The higher score is:n)ifprintf(%d %s %n, else ifprintf(%d %s %n,elsprintf(%d %s %n, printf(%d %s %n,return 0; 3、有 3 个候选人,每个选民只能投票选一人,要求编一个统计选票的程序,先后输入被选人的名字,最后输出各人得票结果。 #include #include struct Person char name20
3、; int count; leader3= “ Li ” ,0, “ Zhang ” ,0, int main() int i,j; char leader_name20; “ Sun” ,0; for (i=1;i=10;i+) scanf( “ %s” ,leader_name); for(j=0;j3;j+if(strcmp(leader_name, )=0) leaderj.count+for(i=0;i3;i+) n“ ,, leaderi.count)return 0; 4、有 n 个学生的信息 (包括学号、姓名、成绩 ),要求按照成
4、绩的高低顺序输出各学生的信息。 #include struct Student int num; char name20; float score; ; int main() struct Student 106,Li, 108, “ 110,” “ Fun” , 100struct Student tempconst int n = 5 ; int i,j,k; printf(The order is:n)for(i=0;in-1;i+) k=i; for(j=i+1;jstuk.score)k=jtemp=stukstuk=stuistui=temfor(i=0;in;i+printf(m
5、 %8s %nstui.num,,stui.score)printf(n)return 0; 5、通过指向结构体变量的指针变量输出结构体变量中成员的信息。 #include #include int main() struct Student long numchar name20char sexfloat score; struct Student stu_1struct Student * pp=&stu_1=10101strcpy, “ Li Lin ” )=M ; =; n”,p-.numprintf(name:%sn, ); n”,p-.sex)pri
6、ntf( ” score:%n” ,return 0; 6、有 3 个学生的信息,放在结构体数组中,要求输出全部学生的信息。 #include struct Student int num; char name20; char sexint age; ; 104,Wang Min,F,20 ; int main() struct Student *pprintf( No. Name sex agen)for(p=stu;pnum, p-name, p-sex, p-age)return 0; 7、有 n 个结构体变量,内含学生学号、姓名和 3 门课程的成绩。要求输出平均成绩最高的 学生的信息
7、(包括学号、姓名、 3 门课程成绩和平均成绩 )。 #include #define N 3 struct Student int numchar name20float score3float aver; ; int main() void input(struct Student stu)struct Student max(struct Student stu)void print(struct Student stu)struct Student stuNinput(stu)print(max(stu)return 0; void input(struct Student stu) i
8、nt i; printf( 请输入各学生的信息:学号、姓名、三门课成绩 :n); for(i=0;iN;i+) scanf(%d %s %f %f %f,&stui.num,,&stui.score0,&stui.score1,&stui.score2 ); stui.aver=(stui.score0+stui.score1+stui.score2)/ struct Student max(struct Student stu) int i,m=0for(i=0;istum.aver) m=ireturn stum; void print(struct Student st
9、ud) printf(n 成绩最高的学生是 :n); printf( 学号 :%dn 姓名 :%sn 三门课成绩 :%,%,%n 平均成绩 :%n,0,1,2, 8、有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业、班级。教师的数据包括:姓名、号码、性别、职业、职务。要求用同一个表格来处理。 #include union Cate int claschar position10; ; struct int numchar name10char sexchar jobunion Categ category person2; int main() int ifor(
10、i=0;i2;i+scanf(%d %s %c %c “ ,&personi.num, &, &personi.sex,&personi.job)if(personi.job = sscanf(%d “ ,&personielse if(personi.job = t ) scanf( “ %s” ,personi.else; printf( “ Input error! ” ); printf(n)for(i=0;i2;i+if (personi.job = s printf(%-6d%-10s%-4c%-4c-10dn,personi.num,personiname
11、,personi.sex,personi.job, personi.elsprintf(%-6d%-10s%-4c%-4c-10sn,personi.num,personiname,personi.sex, personi.jobpersonireturn 0; 9、编程,输入 2 个时刻 , 定义一个时间结构体类型 (包括时分秒) ,计算 2 个时刻之间的时间差。 #include typedef struct Mytime int hour; int min; int sec; T; int main() T t1, t2, t3; int sec1, sec2, sec3; printf
12、( 输入两个时间值,以 XX:XX:XX的格式 n); scanf(%d:%d:%d, , , ; scanf(%d:%d:%d, , , ; sec1 = * 3600 + * 60 + ; sec2 = * 3600 + * 60 + ; if( sec1 = sec2 ) sec3 = sec1 - sec2; else sec3 = sec2 - sec1; = sec3 / 3600; sec3 %= 360= sec3 /60; = sec3 ; printf( 时间差是 %d 小时 %d 分 %d 秒 n, , , ; return 0; 10、编程题:时间换算。用结构体表示时间(时:分:秒) ,输入一个时
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业内部沟通协作平台建设方案
- 江西省九江市都昌县2024-2025学年八年级上学期期末生物试题(含答案)
- 北京延庆区2024-2025学年高二上学期期末生物学试题(含答案)
- 三农用物资采购管理作业指导书
- 从理论到实践科学探究活动课
- 青稞种植知识培训课件
- 电商直播平台搭建与运营服务协议
- 数学王国里的智慧读后感
- 电子支付平台推广专项资金协议
- 智能供应链管理服务合同
- 2025中高考百日誓师大会教师表态发言稿:百日竞渡立壮志 师生同心铸辉煌
- 2025体育单招英语备考100个高频名词精讲(精校打印版)
- 台球馆装修合同模板及明细
- DeepSeek:从入门到精通3天教程
- 2024-2025学年人教版数学七下 第七章 相交线与平行线(含答案)
- GB/T 44994-2024声学助听器验配管理
- 2025年上海铁路局集团公司招聘笔试参考题库含答案解析
- 2024年04月北京中信银行总行社会招考(423)笔试历年参考题库附带答案详解
- 2025年中国航天科工招聘笔试参考题库含答案解析
- 儿童教育总经理聘任合同
- 4《公民的基本权利和义务》(第2课时)教学实录-2024-2025学年道德与法治六年级上册统编版
评论
0/150
提交评论