{struct EXAMPLE{struct{ int x; inty; }in; int a; int b; }e;
e.a=1;e.b=2; e.in.x=e.a*e.b; e.in.y=e.a+e.b;
printf(“%d,%d”,e.in.x,e.in.y); }
【题39】 以下程序用以输出结构体变量bt所占内存单元的字节数,请在( )内填上适当内容. struct ps {
double i; char arr[20]; }; main()
{ struct ps bt;
printf(“bt size : %d\\n”,(sizeof(struct ps )); }
【题40】以下程序用来按学生姓名查询其排名和平均成绩.查询可连续进行,直到键入 0 时结束,请在( )内填入正确内容. #include
(struct student)stu[]={ 3,”Tom”,89.3, 4,”Mary”,78.2 , 1,”Jack”,95.1, 2,”Jim”,90.6, }; main()
{ char str[10]; int I;
do { printf(“Entre a name:”); scanf(“%s”,str); for(i=0;i if( (strcmp(str,stu[i].name)++0) ) { printf(“name : %8s\\n,”stu[i].name); printf(“rank :%3s\\n”,stu[i].rank); printf(“average :0.5s\\n”,stu[i].score); ( (break) ); } if(i>=NUM) printf(“Not found\\n”); } while(strcmp(str,”0”)! = 0); } 【题41】设有三人的姓名和年龄存在结构数组中,以下程序输入三人中年龄居中者的姓名和年龄,请在( )内填入正确内容. Static struct man { char name[20]; int age; } person[]={“li-ming”,18, “wang-hua”,19, “zhang-ping”,20 }; main(0 { int I,j,max,min; max=min=person[0].age; for(i=1;i<3;i++) if(person[i].age if(person[i].age! = max (&&) person[i].age! = min) { printf(“%s %d\\n”,person[i].name,person[i].age); break; } } 【题42】以下程序用”比较计数”法对结构数组 a 按字段 num 进行降序排列.” 比较计数”法的基本思想是:通过另一字段 con 记录 a 中小于某一特定关键字的元素的个数.待算法结束,a[i].con 就是a[i].num 在 a 中的排序位置.请在( )内填入正确内容. #define N 8 struct c { int num; int con; } a[16] main() {int i,j; for(i=0;i {scanf(“%d”,&a[i].num); a[i].con=0; } for(i=N-1;i>=1;i--) for(j=i-1;j>=0;j--) if(a[i].num printf(“%d,%d\\n”a[i].num,a[i]con); } 【题43】 若已定义: struct num {int a; int b; float f; } n={1,3,5.0}; struct num * pn = &n; 则表达式 pn ->b/n.a*++pn->b的值是【12】,表达式 (*pn).a+pn->f的值是【6.0】 【题44】以下程序的功能是计算并打印复数的差。请在【】内填入正确内容。 struct comp {float re; float im; }; struct comp *m(x,y) struct comp *x,*y; {【struct comp*z】; z=(struct comp * )malloc(sizeof(struct comp)); z->re=x->re-y->re; z->im=x->im-y->im; return(【z】); } main() {struct comp *t; struct comp a,b; a.re=1; a.im=2; b.re=3; b.im=4; t=m(【&a&b】); printf(“z.re=%f , z.im=%f”,t->re,t->im); } 【题45】以下程序调用readrec函数把10名学生的学号、姓名、四项成绩以及平均分放在一个结构体数组里,学生的学号、姓名、和四项成绩由键盘输入,然后计算出平均分放在结构体对应的域中,调用writerec函数输出10名学生的记录.请在【 】内填入正确内容. #include { char num[5] , name[10]; int s[4]; int ave; }; main() {struct stud st[30]; int i , k; for(k=0;k<10;k++) readrec(&st[k]); writerec(st); } readrec( struct stud * rec) int i , sum; char ch; gets(rec->num); gets(rec->name); for(i=0;i<4;i++) scanf(“%d”, 【&rec->s[i]】); ch=getchar(); sum=0; for(i=0;i<4;i++ ) sum +=【rec->s[i]】; rec->ave=sum/4.0; } writerec(struct stud * s) { int k,j; for(k=0;k<10;k++) { printf(“NUM:%s MANE:%s\\n”,(*(s+k)).num,(*(s+k)). name ); for(i=0;i<4;i++) printf(“ MARK:]”, 【(*(s+k)).s[i]】); printf(“AVE:]\\n”,(*(s+k)).ave); } } 【题46】以下程序的运行结果是【7,3】。 struct ks {int a; int *b; } s[4],*p; main() { int n=1 , i; printf(“\\n”); for(i=0;i<4;i++) { s[i].a=n; s[i].b=&s[i].a; n=n+2; } p=&s[0; p++; printf(“%d,%d\\n”,(++p)->a,(p++)->a); } 【题47】结构数组中存有三人的姓名和年龄,以下程序输出三人中最年长者的姓名和年龄 。请在【 】内填入正确内容。 static struct man { char name[20]; int age; } person[ ]={“li-ming”,18, “wang-hua”,19, “zhang-ping”,20 }; main() { struct man *p,*q; int old=0; p=person; for(;p【dt[leap][i]】; p++) if (old age) {q=p;【d】;} printf(“%s%d”,【p】); } 【题48】 以下程序运行结果为【 19 83.5 zhang l9 83.5zhang