请问我的程序哪里出错了,谢谢!
代码如下:
#include <stdio.h>
void main()
{
int year1,month1,date1,days1=0,year2,month2,date2,days2=0,n,m,k,days;
printf("请输入出生年月日:\n");
scanf("%d%d%d",&year1,&month1,&date1);
printf("请输入计算天的年月日:\n");
scanf("%d%d%d",&year2,&month2,&date2);
n=year1;
if(year1<=year2-1)
{
for(n=year1,days=0;n<=year2-1;n++) //统计year1到year2-1的天数
{
if(n%4==0 && n%100!=0 || n%400==0)
days+=366;
else days+=365;
}
}
else days=0;
printf("year1到year2-1的天数: %d\n",days);
for(m=1;m<=month1-1;m++)//计算出出生日是当年的days1天
{
if(n%4==0 && n%100!=0 || n%400==0)
{
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
days1+=31;
else if(m==2)
days1+=29;
else days1+=30;
}
else
{
if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12)
days1+=31;
else if(m==2)
days1+=28;
else days1+=30;
}
}
days1+=date1;
for(k=1;k<=month2-1;k++)//计算出计算日是当年的days2天
{
if(year2%4==0 && year2%100!=0 || year2%400==0)
{
if(k==1 || k==3 || k==5 || k==7 || k==8 || k==10 || k==12)
days2+=31;
else if(k==2)
days2+=29;
else days2+=30;
}
else
{
if(k==1 || k==3 || k==5 || k==7 || k==8 || k==10 || k==12)
days2+=31;
else if(k==2)
days2+=28;
else days2+=30;
}
}
days2+=date2;
printf("%d\n",days+days2-days1);
}