首页 > 代码库 > 抄写例题作业1
抄写例题作业1
例9.1:
#include<stdio.h> int main() {struct Student //声明结构体类型struct Student { long int num; //以下四行为结构体的成员 char name[20]; char sex; char addr[20]; }w={01,"Yu Jinchi",‘M‘,"Beijing Road"}; //定义结构体变量a并初始化 printf("NO.:%ld\nname:%s\nsex:%C\naddress:%s\n",w.num,w.name,w.sex,w.addr); //输出结构体所有成员,也就是学生的所有信息 return 0; }
NO.:1
name:Yu Jinchi
sex:M
address:Beijing Road
--------------------------------
Process exited after 0.104 seconds with return value 0
请按任意键继续. . .
例9.2:
#include<stdio.h> int main() { struct Student //声明结构体类型 struct Student { int num; char name[20]; float score; }student1,student2; //定义两个结构体变量student1,student2 scanf("%d %s %f",&student1.num,student1.name,&student1.score); //输入学生1的数据 scanf("%d %s %f",&student2.num,student2.name,&student2.score); //输入学生1的数据 printf("The higher score is:\n"); //输出最高分 if(student1.score>student2.score) //用if语句进行大小比较,输出分数较大者 printf("%d %s %6.2f\n",student1.num,student1.name,student1.score); else if(student1.score<student2.score) printf("%d %s %6.2f\n",student2.num,student2.name,student2.score); else { printf("%d %s %6.2f\n",student1.num,student1.name,student1.score); printf("%d %s %6.2f\n",student2.num,student2.name,student2.score); } return 0; }
01 yujinchi 666
02 pipixia 665
The higher score is:
1 yujinchi 666.00
--------------------------------
Process exited after 53.43 seconds with return value 0
请按任意键继续. . .
抄写例题作业1
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。