1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 |
#include <stdio.h> int main( void ){ int
year1, month1, day1, midDay; int
year2, month2, day2; int
totalDate1; int
totalDate2; printf( "请输入两个日期 年 月 日\n" ); scanf( "%d%d%d" , &year1, &month1, &day1); printf( "%d,%d,%d\n" , year1, month1, day1); printf( "\n" ); scanf( "%d%d%d" , &year2, &month2, &day2); printf( "%d,%d,%d\n" , year2, month2, day2); switch (month1){ case
1:totalDate1=day1; break ; case
2:totalDate1=31+day1; break ; case
3:totalDate1=59+day1; break ; case
4:totalDate1=90+day1; break ; case
5:totalDate1=120+day1; break ; case
6:totalDate1=151+day1; break ; case
7:totalDate1=181+day1; break ; case
8:totalDate1=212+day1; break ; case
9:totalDate1=243+day1; break ; case
10:totalDate1=273+day1; break ; case
11:totalDate1=304+day1; break ; case
12:totalDate1=334+day1; break ; } switch (month2){ case
1:totalDate2=day2; break ; case
2:totalDate2=31+day2; break ; case
3:totalDate2=59+day2; break ; case
4:totalDate2=90+day2; break ; case
5:totalDate2=120+day2; break ; case
6:totalDate2=151+day2; break ; case
7:totalDate2=181+day2; break ; case
8:totalDate2=212+day2; break ; case
9:totalDate2=243+day2; break ; case
10:totalDate2=273+day2; break ; case
11:totalDate2=304+day2; break ; case
12:totalDate2=334+day2; break ; } if (year1%4==0&&year1%100!=0||year1%400==0){ //判断是否是闰年 if (month1>2){ totalDate1++; } } if (year2%4==0&&year2%100!=0||year2%400==0){ if (month2>2){ totalDate2++; } } <span style= "color: rgb(255, 102, 0);" > if (year1==year2){ midDay=totalDate2-totalDate1; //同一年就用这年的第几天天数互减 } else { midDay=365-totalDate1+totalDate2+(year2-year1-1)*365; //先每年定为365统计相识的天数 int
i; for (i=year1;i<year2;i++){ if (i%4==0&&i%100!=0||i%400==0){ midDay++; //然后判断是否存在闰年 有了就再加一天 } } } </span> printf( "我们相识%d天\n" , midDay); } |
原文:http://www.cnblogs.com/u635883/p/3761983.html