Easy Tutorial
❮ C Examples Ascii Value Character C Function Free ❯

C Exercise Example 78

C Language Classic 100 Examples

Title: Find the oldest person and print their details. Identify any issues in the program.

Program Analysis: None.

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
struct man{
    char name[20];
    int  age;
}
person[3]={"li",18,"wang",25,"sun",22};
int main()
{
    struct man *q,*p;
    int i,m=0;
    p=person;
    for(i=0;i&lt;3;i++)
    {
        if(m<p->age)
        {
            m=p->age;
            q=p;
        }
        p++;
    }
    printf("%s %d\n",q->name,q->age);
    return 0;
}

The above example outputs the following result:

wang 25

C Language Classic 100 Examples

❮ C Examples Ascii Value Character C Function Free ❯