首页 > 代码库 > *分支-13. 计算天数
*分支-13. 计算天数
1 /* 2 * Main.c 3 * B13-分支-13. 计算天数 4 * Created on: 2014年6月12日 5 * Author: Boomkeeper 6 * 7 ******测试又是木有完全通过啊********* 8 */ 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 #define JANUARY 31 14 #define FEBRUARY 28 15 #define MARCH 31 16 #define APRIL 30 17 #define MAY 31 18 #define JUNE 30 19 #define JULY 31 20 #define AUGUST 31 21 #define SEPTEMBER 30 22 #define OCTOBER 31 23 #define NOVEMBER 30 24 25 int day_of_year; 26 int year,month,day; 27 28 void output_leap_year() 29 { 30 if(month==1) 31 day_of_year=day; 32 if(month==2) 33 day_of_year=JANUARY+day; 34 if(month==3) 35 day_of_year=JANUARY+FEBRUARY+day+1; 36 if(month==4) 37 day_of_year=JANUARY+FEBRUARY+MARCH+day+1; 38 if(month==5) 39 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+day+1; 40 if(month==6) 41 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+day+1; 42 if(month==7) 43 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+day+1; 44 if(month==8) 45 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+day+1; 46 if(month==9) 47 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+day+1; 48 if(month==10) 49 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+day+1; 50 if(month==11) 51 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+day+1; 52 if(month==12) 53 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+NOVEMBER+day+1; 54 55 printf("%i\n",day_of_year); 56 } 57 58 void output_non_leap() 59 { 60 if(month==1) 61 day_of_year=day; 62 if(month==2) 63 day_of_year=JANUARY+day; 64 if(month==3) 65 day_of_year=JANUARY+FEBRUARY+day; 66 if(month==4) 67 day_of_year=JANUARY+FEBRUARY+MARCH+day; 68 if(month==5) 69 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+day; 70 if(month==6) 71 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+day; 72 if(month==7) 73 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+day; 74 if(month==8) 75 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+day; 76 if(month==9) 77 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+day; 78 if(month==10) 79 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+day; 80 if(month==11) 81 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+day; 82 if(month==12) 83 day_of_year=JANUARY+FEBRUARY+MARCH+APRIL+MAY+JUNE+JULY+AUGUST+SEPTEMBER+OCTOBER+NOVEMBER+day; 84 85 printf("%i\n",day_of_year); 86 } 87 int main() 88 { 89 char m,n; 90 91 scanf("%4i %c %2i %c %2i",&year,&m,&month,&n,&day); 92 printf("input successful\n%i %i %i\n",year,month,day); 93 94 if(month<=0 || day<=0) 95 exit(0); 96 if(month>12 || day>31) 97 exit(0); 98 99 if((year%4==0) && (year%400!=0))100 {101 //闰年102 output_leap_year();103 }104 else105 {106 if(year%400==0)107 {108 //还是闰年109 output_leap_year();110 }111 else112 {113 //不是闰年114 output_non_leap();115 }116 }117 118 return 0;119 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。