计算出生日到计算日的总天数
请高手帮忙看看,有错误不知哪里错了,谢谢。#include <stdio.h>
int is_leap_year(int year)
{
int leap;
if(year%4==0&&year%100!=0||year%400==0)leap=1;
else leap=0;
return leap;
}
int len_of_month(int year,int month)
{
int month_days;
if(month==2)
if(is_leap_year(year))month_days=29;
else month_days=28;
else if(month==4||month==6||month==9||month==11)month_days=30;
else month_days=31;
return month_days;
}
int len_of_days(int year,int month,int date)
{
int total_days,n;
for(n=1,total_days=0;n<month;n++)
total_days+=len_of_month(year,n);
total_days+=date;
return total_days;
}
void main()
{
int year1,month1,date1,days1,year2,month2,date2,days2,days3,days,n;
printf("Please input year1,month1,date1:");
scanf("%d,%d,%d",&year1,&month1,&date1);
printf("Please input year2,month2,date2:");
scanf("%d,%d,%d",&year2,&month2,&date2);
days1=len_of_days(year1,month1,date1);
days2=len_of_days(year2,month2,date2);
for(n=year1,days3=0;n<year2;n++)
{
days3+=(is_leap_year(year1)?366:365);
}
days=days3+days2-days1;
printf("%d/%d/%d~%d/%d/%d is the %d Day\n",year1,month1,date1,year2,month2,date2,days);
getch();
return 0;
}