# include≤ stdio. h> int maino struct Student d long int num; char name[20]; char sex: char addr[20] fa=10101 Li Lin"M 123 Beijing road" ]i anum=10010;对引用结构体变量中的成员 printf(%sWn"a)不对 企图用结构体变量名输出所有成员的值 }
#include <stdio.h> int main() {struct Student { long int num; char name[20]; char sex; char addr[20]; }a={10101,“Li Lin”,‘M’, “123 Beijing Road”}; …… } a.num=10010; 对 printf(“%s\n”,a); 不对 企图用结构体变量名输出所有成员的值 引用结构体变量中的成员
# include≤ stdio. h> int maino struct Student d long int num; char name[20]; char sex: char addr[20] fa=10101 Li Lin"M 123 Beijing road" ]i struct student b 同类型的结构体变量可互 b=a;对 相赋值 bnum++;对成员可像普通变量那样进 行各种运算 }
#include <stdio.h> int main() {struct Student { long int num; char name[20]; char sex; char addr[20]; }a={10101,“Li Lin”,‘M’, “123 Beijing Road”}; …… } b=a; 对 struct Student b; b.num++; 对 同类型的结构体变量可互 相赋值 成员可像普通变量那样进 行各种运算
# include≤ stdio. h> int maino struct Student d long int num; char name[20]; char sex: char addr[20] fa=10101 Li Lin"M 123 Beijing Road "y scanf(9ld"r&anum);对(引用变量成员的地址) printf("%o&a);对(引用变量的地址 scanf(o/old, %s,/oc, os\n"&a)i ti (不能整体读入结构体变量)
#include <stdio.h> int main() {struct Student { long int num; char name[20]; char sex; char addr[20]; }a={10101,“Li Lin”,‘M’, “123 Beijing Road”}; } scanf(″%ld″,&a.num); 对(引用变量成员的地址) printf(″%o″,&a); 对(引用变量的地址) scanf(“%ld,%s,%c,%s\n”,&a); 错 (不能整体读入结构体变量)
# include≤ stdio. h> int maino struct Date int month; int day; int year ji struct stu int numi char name[201; char sexint age struct Date birthdayi char addr[30]; ya,bi a birthday. month=12;对 aage=10;bage=9;对 sum=aage+bage;对
#include <stdio.h> int main() { struct Date { int month; int day; int year; }; struct Stu { int num;char name[20]; char sex;int age; struct Date birthday; char addr[30]; }a,b; a.birthday.month=12; 对 a.age=10; b.age=9; 对 sum=a.age+b.age; 对
例92输入两个学生的学号、姓名和成绩 ,输出成绩较高学生的学号、姓名和成绩
例9.2 输入两个学生的学号、姓名和成绩 ,输出成绩较高学生的学号、姓名和成绩