C Exercise Example 78
100 cases of classic C language
Title: Find the oldest person, and output. Please find the program you have any questions.
Program Analysis: None.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> struct man{ char name[20]; int age; } person[3]={"li",18,"wang",19,"sun",22}; int main() { struct man *q,*p; int i,m=0; p=person; for(i=0;i<3;i++) { if(m<p->age)m=p->age; q=p++; } printf("%s %d\n",q->name,q->age); return 0; }
Run the above example output is:
sun 22