c语言编程,输入年月日,判断是什么中国传统节日
时间: 2023-12-17 20:02:12 浏览: 35
以下是一个简单的 C 语言程序,输入年月日,判断是什么中国传统节日:
```c
#include <stdio.h>
int main()
{
int year, month, day;
printf("请输入年月日(用空格分隔):");
scanf("%d %d %d", &year, &month, &day);
if (month == 1 && day == 1)
{
printf("元旦节\n");
}
else if (month == 2 && day == 2)
{
printf("龙抬头\n");
}
else if (month == 5 && day == 5)
{
printf("端午节\n");
}
else if (month == 8 && day == 15)
{
printf("中秋节\n");
}
else if (month == 10 && day == 1)
{
printf("国庆节\n");
}
else
{
printf("没有节日\n");
}
return 0;
}
```
程序中用 if 和 else if 语句分别判断输入的月份和日期是否与各个传统节日相符,如果相符则输出相应的节日名称,否则输出“没有节日”。其中,元旦节为每年的1月1日,龙抬头为每年的农历二月初二,端午节为每年的农历五月初五,中秋节为每年的农历八月十五,国庆节为每年的10月1日。