/*求两个日期之间的天数*/ |
#include "stdio.h" |
void main() |
{ |
int i,y,m1,m2,d1,d2; |
int d=0; |
printf ( "请输入年月日:\n如2010年1月3日和3月4日输入格式为2010 1 3 3 4\n" ); |
scanf ( "%d%d%d%d%d" ,&y,&m1,&d1,&m2,&d2 ); |
y= ( y%4==0&&y%100!=0||y%400==0 ) ?1:0; |
for ( i=m1; i<m2; i++ ) |
switch ( i ) |
{ |
case 1: |
case 3: |
case 5: |
case 7: |
case 8: |
case 10: |
case 12: |
d+=31; |
break ; |
case 4: |
case 6: |
case 9: |
case 11: |
d+=30; |
break ; |
case 2: |
d=d+28+y; |
break ; |
} |
printf ( "%d\n" ,d+d2-d1 ); |
} |