#include<stdio.h>
#define judge(y) (y%4==0)&&(y%100!=0)||(y%400==0)
int allday(int x);
int month1[]={31,28,31,30,31,30,31,31,30,31,30,31};
int month2[]={31,29,31,30,31,30,31,31,30,31,30,31};
void main()
{ int i;
int yea1,yea2,mon1,mon2,day1,day2;
int *p;
long jia_day1=0;
long jia_day2=0;
long jia_day3=0;
long jia_day4=0;
long jia_all=0;
printf("请输入第一个年月份\n");
scanf("%d %d %d",&yea1,&mon1,&day1);
printf("请输入第二个年月份\n");
scanf("%d %d %d",&yea2,&mon2,&day2);
if(judge(yea1)) printf("%d是闰年\n",yea1);
if(judge(yea2)) printf("%d是闰年\n",yea2);
if(yea1>yea2)
{ if(judge(yea2)) p=month2;
else p=month1;
jia_day1=*(p+mon2-1)-day2;
for(i=mon2;i<=11;i++)
jia_day2=jia_day2+*(p+i);
for(i=yea2+1;i<yea1;i++)
jia_day3=jia_day3+allday(i);
if(judge(yea1)) p=month2;
else p=month1;
for(i=1;i<mon1;i++)
jia_day4=jia_day4+*(p+i-1);
jia_all=jia_day1+jia_day2+jia_day3+jia_day4+day1;
printf("%d%d%d比%d%d%d迟%d天\n",yea1,mon1,day1,yea2,mon2,day2,jia_all);
}
else if(yea1<yea2)
{ if(judge(yea1)) p=month2;
else p=month1;
jia_day1=*(p+mon1-1)-day1;
for(i=mon1;i<=11;i++)
jia_day2=jia_day2+*(p+i);
for(i=yea1+1;i<yea2;i++)
jia_day3=jia_day3+allday(i);
if(judge(yea2)) p=month2;
else p=month1;
for(i=1;i<mon2;i++)
jia_day4=jia_day4+*(p+i-1);
jia_all=jia_day1+jia_day2+jia_day3+jia_day4+day2;
printf("%d%d%d比%d%d%d迟%d天\n",yea2,mon2,day2,yea1,mon1,day1,jia_all);
}
else
{ if(judge(yea1)) p=month2;
else p=month1;
if(mon1>mon2)
{ jia_day1=*(p+mon2-1)-day2;
for(i=mon2+1;i<mon1;i++)
jia_day2=jia_day2+*(p+i-1);
jia_all=jia_day1+jia_day2+day1;
printf("第一个时间比第二个时间迟%d天\n",jia_all);
}
else if(mon1<mon2)
{ jia_day1=*(p+mon1-1)-day1;
for(i=mon1+1;i<mon2;i++)
jia_day2=jia_day2+*(p+i-1);
jia_all=jia_day1+jia_day2+day2;
printf("第一个时间比第二个时间早%d天\n",jia_all);
}
else
{if(day1>day2)
printf("第一个时间比第二个时间迟%d天\n",(day1-day2));
else if(day1<day2)
printf("第一个时间比第二个时间早%d天\n",(day2-day1));
else printf("这俩个时间相等\n");
}
}
}
int allday(int x)
{ int y;
if(((x%4==0)&&(x%100!=0))||((x%100==0)&&(x%400==0)))
{y=366; printf("在这俩个数据中:%d是闰年\n",x);}
else y=365;
return (y);
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |