帮我写一个C语言日期计算器代码
时间: 2023-03-31 12:03:44 浏览: 250
C写的日期计算器
好的,以下是C语言日期计算器的代码:
```
#include <stdio.h>
int main()
{
int year, month, day, days;
printf("请输入年份:");
scanf("%d", &year);
printf("请输入月份:");
scanf("%d", &month);
printf("请输入日期:");
scanf("%d", &day);
switch(month)
{
case 1:
days = day;
break;
case 2:
days = 31 + day;
break;
case 3:
days = 59 + day;
break;
case 4:
days = 90 + day;
break;
case 5:
days = 120 + day;
break;
case 6:
days = 151 + day;
break;
case 7:
days = 181 + day;
break;
case 8:
days = 212 + day;
break;
case 9:
days = 243 + day;
break;
case 10:
days = 273 + day;
break;
case 11:
days = 304 + day;
break;
case 12:
days = 334 + day;
break;
default:
printf("输入的月份有误!\n");
return ;
}
if((year % 4 == && year % 100 != ) || year % 400 == )
{
if(month > 2)
{
days++;
}
}
printf("%d年%d月%d日是这一年的第%d天。\n", year, month, day, days);
return ;
}
```
希望能够帮到你!
阅读全文