typedef
Completed
Use typedef struct { char name[30]; int age; } Person;. Read n people and print the oldest one's name and age (first on ties).
Input
n, then n lines name age.
Output
name age
Example
Input
3 ann 30 bob 52 cy 41
Output
bob 52
Editor
C
Hints
typedef lets you write Person instead of struct Person.
Solution explanation
Arrays of structs are the C equivalent of a table of records.
Show solution
#include <stdio.h>
typedef struct {
char name[30];
int age;
} Person;
int main() {
int n;
Person people[50];
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%s %d", people[i].name, &people[i].age);
int oldest = 0;
for (int i = 1; i < n; i++) {
if (people[i].age > people[oldest].age) oldest = i;
}
printf("%s %d\n", people[oldest].name, people[oldest].age);
return 0;
}