1 #include<iostream> 2 using namespace std; 3 4 static int daytable[2][13] ={ 5 {0,31,28,31,30,31,30,31,31,30,31,30,31}, 6 {0,31,29,31,30,31,30,31,31,30,31,30,31} 7 }; 8 //返回某年某月的某天是该年的第多少天 9 int day_of_year(int year ,int month,int day) 10 { 11 int i,leap; 12 leap = ((year %4 ==0 && year%100 != 0 )||( year %400 == 0)); 13 for ( i = 1; i < month;i++) 14 { 15 day += daytable[leap][i]; 16 } 17 18 return day; 19 } 20 //返回某年的第多少天是该年的几月几号 21 void month_day(int year ,int yearday ,int *pmonth , int *pday) 22 { 23 int i,leap; 24 leap = ((year %4 ==0 && year%100 != 0 )||( year %400 == 0)); 25 for (i = 1; yearday > daytable[leap][i] ; i++) 26 { 27 yearday -= daytable[leap][i]; 28 } 29 *pmonth = i; 30 *pday = yearday; 31 } 32 void main() 33 { 34 cout<<day_of_year(1988,8,2)<<endl; 35 int month,day; 36 month_day(1988,325,&month,&day); 37 cout<<month<<"月"<<day<<"号"; 38 cout<<endl; 39 }