作者在 2014-03-15 23:45:45 发布以下内容
#include <stdio.h>
main()
{float y1,y2,m1,d1,m2,d2;
int i,j,d,rn;
printf("请输入两日期中各自的年、月、日:");
scanf("%f,%f,%f,%f,%f,%f",&y1,&m1,&d1,&y2,&m2,&d2);
if(y1<y2)
for(i=y1;i<y2;i++)
{ rn=((i%4==0&&i%100!=0)||i%400==0)?1:0;
for(j=m1;j<m2;j++)
switch(j)
{case 1: case 3: case 5: case 7: case 8: case 10: case 12:
d+=30;break;
case 2:d=d+28+rn;break;
case 4: case 6: case 9: case 11:
d+=31;break;
}
d=d+-d1+d2+365;
}
printf("%d\n",d);
}
main()
{float y1,y2,m1,d1,m2,d2;
int i,j,d,rn;
printf("请输入两日期中各自的年、月、日:");
scanf("%f,%f,%f,%f,%f,%f",&y1,&m1,&d1,&y2,&m2,&d2);
if(y1<y2)
for(i=y1;i<y2;i++)
{ rn=((i%4==0&&i%100!=0)||i%400==0)?1:0;
for(j=m1;j<m2;j++)
switch(j)
{case 1: case 3: case 5: case 7: case 8: case 10: case 12:
d+=30;break;
case 2:d=d+28+rn;break;
case 4: case 6: case 9: case 11:
d+=31;break;
}
d=d+-d1+d2+365;
}
printf("%d\n",d);
}