若已有结构定义“struct DATE{ int year; int mouth; int day; } ;”,请写出一条语句,该语句定义d为上述结构类型变量,并同时为其成员year, mouth, day依次赋初值2009、10、1:()。
查看答案
以下程序中函数fun的功能是统计person所指结构数组中所有性别(sex)为M的记录的个数,并作为函数值返回,请填空。#defin N 3typedef struct { int num; char name[10]; char sex; } SS;int fun(SS person[ ]){int i, n = 0;for(i = 0; i < N; i++)if(() == 'M') n++;return n;}int main(void){SS W[N] = { {1,"AA",'F'}, {2,"BB",'M'}, {3,"CC",'M'} }; int n;n = fun( W ); printf("n=%d\n”, n);}
下列程序的功能是输入5个联系人信息,统计年龄分布情况,请填空。struct address{char street[20];int code;int zip; } ;struct nest_friendslist {char name[10];int age;char teltphone[13];struct address addr; } f;int main(void){int i, count1, count2, count3;count1 = count2 = count3 = 0;for(i = 1; i <= 5; i++ ){scanf("%s%d%s", f.name, &f.age, f.teltphone);(); /* 输入地址信息*/if(f.age >= 55) count1++;else if(f.age >= 40) count2++;else count3++; }printf("老年人数:%d, 中年人数:%d, 青年人数:%d\n", count1, count2, count3);return 0;}
下列程序的功能是输入某班学生的姓名及数学、英语成绩,计算每位学生的平均分,然后输出平均分最高的学生之姓名及数学、英语成绩。请填空。struct student {char name[10]; int math, eng; flost aver; } ;int fun(struct student s[ ], int n){int k, maxsub = 0;for(k = 0; k < n; k++){() = (s[k].math+s[k].eng) / 2.0;if() maxsub = k;}return maxsub;}int main(void){int i, n, maxn;struct student s[50];scanf("%d", &n);for(i = 0; i < n; i++) scanf(%s%d%d", s[i].name, &s[i].math, &s[i].eng);();printf("%10s%3d%3d\n",s[maxn].name, s[maxn].math, s[maxn].eng);return 0;}}
设有三个人的姓名和年龄存在结构数组中,以下程序输出三个人中年龄居中者的姓名和年龄。请填空。static struct man{char name[20];int age;}person[ ] = { “li-ming”,18,"wang-hua",19,"zhang-ping",20 };int main(void){int i, j, max, min;max = min = person[0].age;for(i = 1; i < 3; i++)if(person[i].age > max) ();else if(person[i].age < min) ();for(i = 0; i < 3; i++)if(person[i].age != max () person[i].age != min){printf("%s%d\n", person[i].name, person[i].age);break; }return 0;}