- #include<stdio.h>
- //1
- struct Date
- {
- int year;
- int month;
- int day;
- };
- //2
- int isRunNian(int nian);
- int isRunNian(int nian)
- {
- return (nian%4==0&&nian%100!=0)||(nian%400==0)?1:0;
- }
- //3
- void totalDaysOfThisYear(struct Date wuse)
- {
- int totalDaysOfThisYear = 0;
- switch (wuse.month) {// 12 月 25日
- case 12:
- totalDaysOfThisYear =totalDaysOfThisYear + 30;
- case 11:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 10:
- totalDaysOfThisYear =totalDaysOfThisYear + 30;
- case 9:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 8:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 7:
- totalDaysOfThisYear =totalDaysOfThisYear + 30;
- case 6:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 5:
- totalDaysOfThisYear =totalDaysOfThisYear + 30;
- case 4:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 3:
- totalDaysOfThisYear =totalDaysOfThisYear + isRunNian(wuse.year)?29:28;
- case 2:
- totalDaysOfThisYear =totalDaysOfThisYear + 31;
- case 1:
- default:
- break;
- }
-
- totalDaysOfThisYear = totalDaysOfThisYear + wuse.day;
- printf("----=------%d\n",totalDaysOfThisYear);
- }
- int main()
- {
- // int result = isRunNian(2008);
- // result?printf("闰年\n"):printf("平年");
- struct Date date = {2015,3,1};
- totalDaysOfThisYear(date);
- return 0;
- }
复制代码 |
|