




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1、把一个学生的信息 (包括学号、姓名、性别、住址 )放在一个结构体变量中,然后输出这 个学生的信息。#include <stdio.h>int main()struct Studentlong int num;char name20;char sex;char addr20;a=10101, “Li Lin ”, M', “123 Beijing Road”;printf("NO.:%ldnname:%sn sex:%cnaddress:%sn",a.num,,a.sex,a.addr); return 0;2、输入两个学生的学号、姓名和成
2、绩,输出成绩较高学生的学号、姓名和成绩 #include <stdio.h>int main() struct Studentint num;char name20;float score;student1,student2; scanf("%d%s%f",&student1.num,, &student1.score);scanf( “ %d%s%”f ,&student2.num,, &student2.score);printf("The higher score
3、 is:n");if (student1.score>student2.score)printf("%d %s %6.2fn",student1.num,, student1.score);else if (student1.score<student2.score)printf("%d %s %6.2fn",student2.num,, student2.score);elseprintf("%d %s %6.2fn",student1.num,student
4、1.name, student1.score);printf("%d %s %6.2fn",student2.num,, student2.score); return 0;3、有 3 个候选人,每个选民只能投票选一人,要求编一个统计选票的程序,先后输入被选 人的名字,最后输出各人得票结果。#include <string.h>#include <stdio.h>struct Person char name20;int count;leader3=“Li ”,0, “ Zhang ” ,0, “ Sun” ,0;int m
5、ain() int i,j;char leader_name20;for (i=1;i<=10;i+) scanf( “ %s” ,leader_name); for(j=0;j<3;j+)if(strcmp(leader_name, )=0)leaderj.count+; for(i=0;i<3;i+)printf("%5s:%dn “ ,, leaderi.count);return 0;4、有 n 个学生的信息 (包括学号、姓名、成绩 ),要求按照成绩的高低顺序输出各学生的信 息。#include <std
6、io.h>struct Student int num; char name20; float score;int main() struct Student stu5=10101,"Zhang",78,10103,"Wang",98.5,10106,"Li",86 ,10108, “Ling ”, 73.5,10110,“; Fun”, 100 struct Student temp;const int n = 5 ;int i,j,k;printf("The order is:n");for(i=0;i&
7、lt;n -1;i+) k=i;for(j=i+1;j<n;j+) if(stuj.score>stuk.score) k=j;temp=stuk; stuk=stui;stui=temp; for(i=0;i<n;i+) printf("%6d %8s %6.2fn", stui.num,,stui.score);printf("n");return 0;5、通过指向结构体变量的指针变量输出结构体变量中成员的信息。#include <stdio.h>#include <string.h>int
8、 main() struct Student long num;char name20;char sex;float score;struct Student stu_1;struct Student * p;p=&stu_1;stu_1.num=10101;strcpy(stu_1.name, “ Li Lin ” ); stu_1.sex='M ;s tu_1.score=89.5;printf("No.:%ldn->”.nu,pm);printf("name:%sn", p ->.name); printf("sex:%
9、cn->”.s,e px);printf( ” score:%5.1fn ” ,stu_1.score); return 0;6、有 3 个学生的信息,放在结构体数组中,要求输出全部学生的信息。#include <stdio.h>struct Student int num;char name20;char sex;int age;struct Student stu3=10101,"Li Lin",'M',18,10102,"Zhang Fun",'M',19,10104,"Wang Min&
10、quot;,'F',20 ;int main() struct Student *p;printf(" No. Name sex agen"); for(p=stu;p<stu+3;p+)printf( “ %5-d2 0%s %2c %4dn ”->,npum, p->name, p - >sex, p->age); return 0;7、有 n 个结构体变量,内含学生学号、姓名和3 门课程的成绩。要求输出平均成绩最高的学生的信息 (包括学号、姓名、 3 门课程成绩和平均成绩 )。#include <stdio.h>
11、;#define N 3struct Student int num;char name20;float score3;float aver;int main() void input(struct Student stu);struct Student max(struct Student stu);void print(struct Student stu);struct Student stuN;input(stu);print(max(stu);return 0;void input(struct Student stu) int i;printf(" 请输入各学生的信息:学
12、号、姓名、三门课成绩 :n"); for(i=0;i<N;i+)scanf("%d %s %f %f %f",&stui.num,,&stui.score0,&stui.score1,&stui.score2); stui.aver=(stui.score0+stui.score1+stui.score2)/3.0;struct Student max(struct Student stu)int i,m=0;for(i=0;i<N;i+)if (stui.aver>stum.aver) m=i;
13、return stum;void print(struct Student stud) printf("n 成绩最高的学生是 :n");printf(" 学 号 :%dn 姓 名 :%sn 三 门 课 成 绩 :%5.1f,%5.1f,%5.1fn 平 均 成 绩:%6.2fn",stud.num,,stud.score0,stud.score1,stud.score2,stud.aver);8、有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职 业、班级。教师的数据包括:姓名、号码、性别、职业、职务。要求用同
14、一个表格来处理。#include <stdio.h>union Categ int clas;char position10; struct int num;char name10;char sex;char job;union Categ categoryperson2;int main()int i;for(i=0;i<2;i+)scanf("%d %s %c %c “ ,&personi.num, &, &personi.sex,&personi.job);if(personi.job = 's&
15、#39;)scanf("%d “ ,&personi.category.clas);else if(personi.job = 't)scanf( “ %s” ,personi.category.position);e lse printf( printf("n");for(i=0;i<2;i+)if (personi.job = s' ) printf("% -6d%-10s%-4c%-4c% -10dn",personi.num,personi. name,personi.sex,personi.job, pe
16、rsoni.category.clas);elseprintf("% -6d%-10s%-4c%-4c%-10sn",personi.num,,personi.sex, personi.job, personi.category.position);return 0;9、编程,输入 2个时刻, 定义一个时间结构体类型(包括时分秒) 间差。#include <stdio.h>typedef struct Mytimeint hour;int min;int sec;Input error!” );,计算 2 个时刻之间的时T;int mai
17、n()T t1, t2, t3;int sec1, sec2, sec3;printf(" 输入两个时间值,以 XX:XX:XX的格式 n");scanf("%d:%d:%d", t1.hour, t1.min, t1.sec);scanf("%d:%d:%d", t2.hour, t2.min, t2.sec);sec1 = t1.hour * 3600 + t1.min * 60 + t1.sec;sec2 = t2.hour * 3600 + t2.min * 60 + t2.sec;if( sec1 >= sec2 )sec3 = sec1 - sec2;elsesec3 = sec2 - sec1;t3.hour = sec3 / 3600;sec3 %= 3600;t3.min = sec3 /60;t3.sec = sec3 %60;printf(" 时间差
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 海外考试自习室租赁与学业辅导支持协议
- 企业级开源软件贡献者代码维护与升级协议
- 教师培训作业上传操作指南
- 2025-2030年切换器专用线缆项目投资价值分析报告
- 海运货代知识培训
- 民航安全管理体系核心要点
- 2025年会计、审计及税务服务项目规划申请报告模范
- 2025年临床试验CRO项目申请报告
- 时间四象限管理法
- 粮食仓储企业绿色经济企业绿色市场分析考核试卷
- 小学思政课《爱国主义教育》
- 抖音个人IP代运营服务合同
- 超实用槽式太阳能光热发电系统设计
- 2023年大北农科技奖奖励办法实施细则
- 09《马克思主义政治经济学概论(第二版)》第九章
- 启动调试期间设备代保管管理制度
- 妇产科学教学课件:女性生殖系统炎症
- 大学关于进一步改进工作作风、密切联系师生的若干规定
- 作风建设试题
- 导线测量等级划分及精度要求
- 国土空间规划一张图建设管理及应用
评论
0/150
提交评论