抄写例题作业1
Posted 于金池
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了抄写例题作业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的主要内容,如果未能解决你的问题,请参考以下文章