版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 、 name,a 、 sex,a、 addr); return 0;2、输入两个
2、学生得学号、姓名与成绩,输出成绩较高学生得学号、姓名与成绩 #include <stdio 、 h>int main() struct Student int num; char name20; float score;student1,student2;scanf("%d%s%f",&student1 、num,student1 、 name, &student1 、 score); scanf( “ %d%s%”f ,&stude、nt2num,student2 、 name, &student2 、 score);print
3、f("The higher score is:n");、 num,student1 、 name, student1 、 score); score)、 num,student2 、 name, student2 、 score);if (student1 、 score>student2 、 score) printf("%d %s %6 、2fn",student1else if (student1 、 score<student2 、 printf("%d %s %6 、2fn",student2elseprintf
4、("%d %s %6 、 2fn",student1 、 num,student1 、 name, student1 、 score); printf("%d %s %6 、 2fn",student2 、 num,student2 、 name, student2 、 score); return 0;3、有 3 个候选人,每个选民只能投票选一人,要求编一个统计选票得程序,先后输入被选 人得名字,最后输出各人得票结果。#include <string 、 h> #include <stdio 、 h> struct Person
5、 char name20;int count;leader3=“Li ”,0, “ Zhang ” ,0, “ Sun” ,0;int main() 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,leaderj 、 name)=0) leaderj 、 count+;for(i=0;i<3;i+)n“ ,leaderi、 name,leaderi 、 count);return 0;4、有 n 个学生
6、得信息 (包括学号、姓名、成绩 ),要求按照成绩得高低顺序输出各学生得信 息。#include <stdio 、 h>struct Student int num; char name20; float score;int main()5,10106,"Li", struct Student stu5=10101,"Zhang",78,10103,"Wang",9886 ,10108, “ Ling73”、,5,10110, “ Fun” ,100;struct Student temp;const int n = 5 ;
7、int i,j,k;printf("The order is:n");for(i=0;i<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 、 name,stui 、 score);printf("n");return 0;5、通过指向结构体变量得指针变量输出结构体
8、变量中成员得信息。#include <stdio 、 h>#include <string 、 h>int 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 ; stu_1、score=89、5; printf("No 、n”p,-
9、>、 num);printf("name:%sn", p-> 、 name); n”,p->、sex);printf( ” score、:%5 n” ,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,&q
10、uot;Zhang Fun",'M',19,10104,"Wang Min",'F',20 ;int main() struct Student *p;printf(" No 、 Name sex agen");for(p=stu;p<stu+3;p+)n” ,-p>num, p->name, p->sex, p->age);printf( “%5d %return 0;7、有 n 个结构体变量,内含学生学号、姓名与3 门课程得成绩。要求输出平均成绩最高得学生得信息 (包括学号、姓名
11、、 3 门课程成绩与平均成绩 )。#include <stdio 、 h>#define N 3 struct 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
12、 Student stu) int i;:n");printf(" 请输入各学生得信息:学号、姓名、三门课成绩for(i=0;i<N;i+)scanf("%d %s %f %f %f",&stui 、num,stui 、name,&stui 、score0,&stui 、score1,&stui 、 score2); stui 、 aver=(stui 、 score0+stui 、 score1+stui 、 score2)/ 3、 0;struct Student max(struct Student stu)i
13、nt i,m=0;for(i=0;i<N;i+)if (stui 、 aver>stum 、 aver) m=i;return stum;void print(struct Student stud) printf("n 成绩最高得学生就是 :n");printf(” 学号:dn 姓名:sn 三门课成绩:5、1f,%5、1f,%5、1fn 平均成绩:6、2fn”,stud、 num,stud、 name,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 category person2; int main()int i;for(i=0;i<2;i+)scanf("%d %s %c %c“,&person、i num, &personi 、 name, &person
15、i 、 sex,&personi、job);if(personi 、job = 's')scanf("%d “ ,&perso、nicategory、clas);else if(personi 、 job = 't ) scanf( “ %s” ,pers、onciategory、position);else printf(printf("n"); for(i=0;i<2;i+)if (personi 、job =s' )printf("%-6d%-10s%-4c%-4c%-10dn",pe
16、rsoni 、 num,personi 、 name,personi 、sex,personi 、 job, personi 、category 、clas) ;Input error! ” );elseprintf("%-6d%-10s%-4c%-4c% -10sn",personi 、 num,personi 、 name,personi 、sex, personi、 job, personi 、category、 position);return 0;9、编程,输入 2个时刻, 定义一个时间结构体类型(包括时分秒) 间差。,计算 2 个时刻之间得时#include &
17、lt;stdio 、 h> typedef struct Mytime int hour;int min;int sec;T;int main()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; else sec3 = sec2 - sec1;t3、hour = sec3 / 3600;sec3 %= 3600;t3、min = sec3 /60;t3、sec = sec3 %6
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 合同协议网络广告协议
- 借款延期合同
- 借款合同借款合同范文
- 《深入解析HTTP协议》课件
- 金钱与期刊:媒体禁制令及一稿多投禁制
- 区块链共识机制与改进算法研究进展
- 生长因子促进膝软骨再生:研究热点的文献计量学分析
- 基于机器视觉的智能车系统设计
- 考虑失效相关性的无人机飞控系统可靠性分配与预计
- 基于蓝牙的LBS系统攻击检测方法研究
- (一模)宁波市2024学年第一学期高考模拟考试 数学试卷(含答案)
- 父母赠与子女农村土地协议书范本
- 集团母子公司协议书
- 中医病证诊断疗效标准
- 南安市第三次全国文物普查不可移动文物-各乡镇、街道分布情况登记清单(表五)
- ITSMS-D-038 问题记录表范本
- 第1课+古代亚非(教学设计)【中职专用】《世界历史》(高教版2023基础模块)
- 新教科版六年级下册科学全册教案
- 物业客服管家的培训课件
- 2024年房地产行业的楼市调控政策解读培训
- 《统计学-基于Python》 课件全套 第1-11章 数据与Python语言-时间序列分析和预测
评论
0/150
提交评论