我对C语言算是刚刚起步,最近想做一道关于计算生日的程序,可现在也没有搞明白,或者说是随便输入两个日期,能知道它们之间的天数,有这样的程序也可以指点一下,先谢谢拉!
#include<stdio.h>
int IsLeap(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
return(0);
}
int main()
{
int year1,month1,day1,year2,month2,day2;
long n=0;
printf("输入起始年份:");
scanf("%d%d%d",&year1,&month1,&day1);
printf("输入结束年份:");
scanf("%d%d%d",&year2,&month2,&day2);
while(year1<year2)
{
if(IsLeap(year1)==1)
{
n=n+366;
}
else
{
n=n+365;
}
year1++;
}
while(month1<month2)
{
switch(month1)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:n=n+31;break;
case 4:
case 6:
case 9:
case 11:n=n+30;break;
case 2:
{
if(IsLeap(year1)==1)
{
n=n+29;
}
else
{
n=n+28;
}
break;
}
}
month1++;
}
n=n+day2-day1;
printf("%ld\n",n);
return(0);
}