找出年龄最大的人,并输出,修改以下程序

#include

#define N 4
static struct man
{ char name[20];
int age;
} person[N]={"li",18,"wang",19,"zhang",20,"sun",22};
main()
{ struct man *q,*p;

int i,m=0;
p=person[0];

for (i=0;i { if (m>p->age)
q=p++;

m=p->age;

}
printf("%s,%d",(*q).name,(*q).age);
}

1个回答

#include "stdio.h"

#define N 4
static struct man
{
    char name[20];
    int age;
} person[N] = { "li", 18, "wang", 19, "zhang", 20, "sun", 22 };
int main()
{
    struct man *q, *p;

    int i, m = 0;
    p = q= &person[0];

    for (i = 0; i < N; i++){ 
        if (m<p->age)
        {
            m = p->age;
            q = p;
        }
        p++;
    }
    printf("%s,%d", (*q).name, (*q).age);
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问