weixin_43907392
weixin_43907392
采纳率66.7%
2018-12-26 20:12 阅读 1.0k

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

#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条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2018-12-26 16:56
    #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);
    }
    
    点赞 1 评论 复制链接分享

相关推荐