#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct dt
{
int year;
int month;
int day;
};
int days(struct dt);
void main()
{
int countday;
struct dt date;
printf("请输入年月日:\n");
scanf_s("%d,%d,%d",&date.year,&date.month,&date.day);
countday=days(date);
printf("日期%d%2d%2d为%d的第%d天",date.year,date.month,date.day,date.year,countday);
system("pause");
}
int days(struct dt date)
{
int result=0;
int year=date.year,month=date.month,day=date.day;
switch(month-1)
{
case 12: result+=31;
case 11: result+=30;
case 10: result+=31;
case 9: result+=30;
case 8: result+=31;
case 7: result+=31;
case 6: result+=30;
case 5: result+=31;
case 4: result+=30;
case 3: result+=31;
case 2: {
if(year%400==0||year%4==0&&year%100!=0)
result+=28;
else result+=29;
}
case 1: result+=31;
}
result+=day;//加上对应的月份的天数
return result;
}
(C)定义一个结构体包括年月日,编写一个函数days,计算该日期在本年中是第几天。
最新推荐文章于 2023-12-05 10:53:18 发布