您的位置:首页 > 编程语言

//有三个学生,编程找出分数最高者以及年龄最小者。

2013-12-19 21:01 399 查看
//有三个学生,编程找出分数最高者以及年龄最小者。
struct stu {
char name[20];
float score;
int age;
};
void g_score(struct stu st[],int arr_len){
int j=0;
float max=st[0].score;
for (int i=1; i<arr_len; i++) {
if (max<=st[i].score) {
max=st[i].score;
j=i;
}
}
for (int i=0; i<arr_len; i++) {
if (st[i].score==max) {
printf("分数最高者为%s\t成绩为%.2f\n",st[i].name,max);
}
}
}
void min_age(struct stu st[],int arr_len){
int j=0;
int min=st[0].age;
for (int i=1; i<arr_len; i++) {
if (min>st[i].age) {
min=st[i].age;
j=i;
}
}
for (int i=0; i<arr_len; i++) {
if (st[i].age==min) {
printf("年龄最小者为%s\t年龄为%d\n",st[i].name,min);
}
}
}

int main(int argc, const char * argv[])
{
struct stu s[3]= {"xiaohei",89,14,"fengxing",89,14,"bingnv",89,16};
g_score(s, 3);
min_age(s, 3);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐