c 语言 zzuli1181 谁的年龄最小 结构体专题

设计一个结构体存储姓名和出生日期(年月日),输入n个朋友的信息,输出年龄最小的朋友的姓名及完整出生日期。示例输入3个朋友,输出年龄最小的Fangfang的出生日期为1985-06-01。
摘要由CSDN通过智能技术生成

/*****
题目描述
设计一个结构体类型,包含姓名、出生日期。其中出生日期又包含年、月、日三部分信息。输入n个好友的信息,输出年龄最小的好友的姓名和出生日期。

输入
首先输入一个整数n(1<=n<=10),表示好友人数,然后输入n行,每行包含一个好友的信息:姓名(不超过20位)以及三个整数,分别表示出生日期的年月日。

输出
输出年龄最小的好友的姓名和出生日期,用空格隔开,出生日期的输出格式见输出样例。

样例输入 Copy
3
Zhangling 1983 2 4
Wangliang 1983 12 11
Fangfang 1985 6 1
样例输出 Copy
Fangfang 1985-06-01
*****/

#include <stdio.h>
#include <stdlib.h>

typedef struct fri
{
   
    char id[22];
    int y,m
根据引用[1]和引用的描述,zzulioj1181是一个关于好友息的问题。根据题目要求,我们需要设计一个结构体类型来存储好友的姓名出生日期,并输入n个好友的息,然后找出年龄最小的好友的姓名出生日期。 以下是一个示例的C语言代码实现: ```c #include <stdio.h> struct Date { int year; int month; int day; }; struct Friend { char name[50]; struct Date birthdate; }; int main() { int n; printf("请输入好友的数量:"); scanf("%d", &n); struct Friend friends[n]; for (int i = 0; i < n; i++) { printf("请输入第%d个好友的姓名:", i+1); scanf("%s", friends[i].name); printf("请输入第%d个好友的出生日期 ):", i+1); scanf("%d %d %d", &friends[i].birthdate.year, &friends[i].birthdate.month, &friends[i].birthdate.day); } struct Friend youngestFriend = friends[0]; for (int i = 1; i < n; i++) { if (friends[i].birthdate.year > youngestFriend.birthdate.year) { youngestFriend = friends[i]; } else if (friends[i].birthdate.year == youngestFriend.birthdate.year) { if (friends[i].birthdate.month > youngestFriend.birthdate.month) { youngestFriend = friends[i]; } else if (friends[i].birthdate.month == youngestFriend.birthdate.month) { if (friends[i].birthdate.day > youngestFriend.birthdate.day) { youngestFriend = friends[i]; } } } } printf("年龄最小的好友是:%s\n", youngestFriend.name); printf("出生日期:%d%d%d\n", youngestFriend.birthdate.year, youngestFriend.birthdate.month, youngestFriend.birthdate.day); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值