黑马程序员技术交流社区
标题:
实现计算具体日期是当年第几天
[打印本页]
作者:
曼卿phyand
时间:
2015-12-1 02:01
标题:
实现计算具体日期是当年第几天
#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);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2