Calculating the difference between the two dates

1 #include <stdio.h>
 2  int LEAP ( int year);                          // leap year returns 1, otherwise it returns 0 
3  int yeardays ( int year, int month The, int Day); // return the first few days of the year 
4  int days ( int year);                          // returns the total number of days in a year 
. 5  int main ( void )
 . 6  {
 . 7      int birth_year, birth_month, birth_day;
 . 8      int TO_YEAR, TO_MONTH, to_day;
 . 9      int day_num = 0;
10     scanf("%d %d %d", &birth_year, &birth_month, &birth_day);
11     scanf("%d %d %d", &to_year, &to_month, &to_day);
12 
13     if (birth_year == to_year)
14     {
15         day_num = yeardays(to_year, to_month, to_day) - yeardays(birth_year, birth_month, birth_day);
16     }
17     else
18     {
19         day_num = days(birth_year) - yeardays(birth_year, birth_month, birth_day) + 1;
20         for (int i = birth_year + 1; i < to_year; i++)
21         {
22             day_num = day_num + days(i);
23         }
24         day_num = day_num + yeardays(to_year, to_month, to_day);
25     }
26 
27     printf("%d\n", day_num);
28 
29     return 0;
30 }
31 int leap(int year)
32 {
33     int ret;
34 
35     if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
36     {
37         ret = 1;
38     }
39     else
40     {
41         ret = 0;
42     }
43 
44     return ret;
45 }
46 int yeardays(int year, int month, int day)
47 {
48     int days = 0;
49     int month_days[2][13] = {
50         {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
51         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
52     };
53     for (int i = 1; i < month; i++)
54     {
55         days = days + month_days[leap(year)][i];
56     }
57     days = days + day;
58 
59     return days;
60 }
61 int years(int year)
62  {
 63      int right;
64      IF (LEAP (Year))
 65      {
 66          K = 366 ;
67      }
 68      else 
69      {
 70          K = 365 ;
71      }
 72  
73      Return right;
74 }

There is an error, not been found.

Guess you like

Origin www.cnblogs.com/2018jason/p/12080294.html