#include<stdio.h>
2
3 int year_loap(int n);//判断形参n是否为润年。返回值1或2.
4 int year_num(int yy,int mm,int dd);//计算当前月份,为这一年的第几天。
5
6 int main()
7 {
8 int year = 2012, month = 5, day =23;
9 int x = 0;
10
11 x = year_num(year,month,day);
12 printf("%d\n",x);
13 }
14
15
16 /*int year_num(int yy,int mm,int dd)
17 {
18 int sum = 0;
19
20 switch(mm)
21 {
22 case 1:sum = dd;break;
23 case 2:sum = 31+dd;break;
24 case 3:sum = 60+dd;break;
25 case 4:sum = 91+dd;break;
26 case 5:sum =121+dd;break;
27 case 6:sum =152+dd;break;
28 case 7:sum =182+dd;break;
29 case 8:sum =213+dd;break;
30 case 9:sum =244+dd;break;
31 case 10:sum =274+dd;break;
32 case 11:sum =305+dd;break;
33 case 12:sum =335+dd;break;
34 }
35 if(1 == year_loap(yy))
36 return sum;
37 else return sum-1;
38 }*/
int year_loap(int n)
42 {
43 int i = 0;
44 if(0 == n%4)
45 {
46 if(0 == n%100)
47 {
48 if(0 == n%400)
49 {
50 return 1;
51 }
52 else return 2;
53 }
54 else return 1;
55 }
56 else return 2;
57 }
58 int year_num(int yy,int mm,int dd)
59 {
60 int a[] = {31,28,31,30,31,30,31,31,30,31,30,31};
61 int i = 0,sum = 0;
62
63 if(mm>2)
64 {
65 for(i = 0;i<mm-1; i++)
66 {
67 sum = sum+a[i];
68 }
69 sum = sum+dd;
70 }
71 else sum = 31+dd;
72 if(1 == year_loap(yy))
73 return sum+1;
74 else return sum;
75 }