#include<stdio.h>
struct Date{
int year;
int month;
int day;
};
int isLeapYear(int year);//判断是否是闰年
int isLeapYear(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return 1;
}
return 0;
}
void days(struct Date someDate);//计算天数
void days(struct Date someDate)
{
int totalDaysFromYearStart = 0;
switch (someDate.month) {
case 12:
totalDaysFromYearStart += 30;
case 11:
totalDaysFromYearStart += 31;
case 10:
totalDaysFromYearStart += 30;
case 9:
totalDaysFromYearStart += 31;
case 8:
totalDaysFromYearStart += 31;
case 7:
totalDaysFromYearStart += 30;
case 6:
totalDaysFromYearStart += 31;
case 5:
totalDaysFromYearStart += 30;
case 4:
totalDaysFromYearStart += 31;
case 3:
totalDaysFromYearStart += 28;
totalDaysFromYearStart += isLeapYear(someDate.year) ? 1 : 0;
case 2:
totalDaysFromYearStart += 31;
case 1:
default:
break;
}
totalDaysFromYearStart += someDate.day;
printf("%d\n",totalDaysFromYearStart);
}
|
|