一、分析
(1)首先分析是否为闰年,若为闰年则2月为29天
(2)其次计算之前的几个月一共有多少天
(3)最终加上该天在月中是多少天
二、源码
1: #include <stdio.h>
2:
3: int Day(int year, int month, int date)
4: {
5: int months[13] = {0, 31, 0, 31, 30,
6: 31, 30, 31, 31, 30,
7: 31, 30, 31};
8: int i, days = 0;
9:
10: if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
11: months[2] = 29;
12: else
13: months[2] = 28;
14:
15: for (i = 1; i < month; ++i)
16: {
17: days += months[i];
18: }
19: days += date;
20: return days;
21: }
22:
23: int main()
24: {
25: printf("the days of 25th May 2010 is %d\n", Day(2010, 5, 25));
26: return 0;
27: }