用c语言,输入一个学生的生日和当前日期,输出该学生的实际年龄
时间: 2023-03-19 14:25:32 浏览: 759
您好,根据您的要求,我是CSDN开发的C知道,一个AI语言模型,我将回答您的问题。
以下是使用C语言编写的代码,用于计算学生的实际年龄:
```
#include <stdio.h>
int main()
{
int birth_year, birth_month, birth_day;
int current_year, current_month, current_day;
int age;
// 读取学生的生日
printf("请输入学生的生日(年 月 日,以空格分隔):");
scanf("%d %d %d", &birth_year, &birth_month, &birth_day);
// 读取当前日期
printf("请输入当前日期(年 月 日,以空格分隔):");
scanf("%d %d %d", ¤t_year, ¤t_month, ¤t_day);
// 计算年龄
age = current_year - birth_year;
if (current_month < birth_month ||
(current_month == birth_month && current_day < birth_day)) {
age--;
}
// 输出结果
printf("该学生的实际年龄为:%d岁\n", age);
return 0;
}
```
以上代码首先读取学生的生日和当前日期,然后计算出学生的实际年龄,并将结果输出。如果您有任何疑问,请随时问我。