void chang(int *a,int *b)
{
int temp
temp=*a
*a=*b
*b=temp
}
int isR(int year)
{
if(year%4==0&&(year%400==0||year%100!=0)) return 1
return 0
}
int check(int *y1,int *m1,int *d1,int *y2,int *m2,int *d2)
{
int mon1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
int mon2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
if(isR(*y1)) mon1[2] = 29
if(isR(*y2)) mon2[2] = 29
if(*m1 <= 0 || *m1 >12 || *m2 <= 0 || *m2 >12 || *d1 <= 0 || *d1 >31)
return 0
if(*d1>mon1[*m1]||*d2>mon2[*m2]) return 0
if(*y1 >*y2)
{
chang(y1,y2)
chang(m1,m2)
chang(d1,d2)
}
return 1
}
int TTD(int year,int month,int day)
{
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
int sum=0
int i=1
if(month <= 0 || month >12 || day >31 || day <= 0 )
return 0
if(day >mon[month]) return 0
if(isR(year)) mon[2] = 29
for(i<=monthi++)
sum+=mon[i-1]
sum+=day
return sum
}
int main()
{
int y1,m1,d1,y2,m2,d2
long sum=0
scanf("%d-%d-%d",&y1,&m1,&d1)
printf("请输入日期2(年-月-日):")
scanf("%d-%d-%d",&y2,&m2,&d2)
if(!check(&y1,&m1,&d1,&y2,&m2,&d2))
{
printf("您输入的日期有误,请检查!") return -1
}
for(int i=y1i<y2i++)
if(isR(i)) sum+=366
else sum+=365
sum-=TTD(y1,m1,d1)
sum+=TTD(y2,m2,d2)
printf("共%ld天\n",abs(sum))
return 0
}
这个只要做一个窗体中包含三个文本框,用于输入出身的年月日,然后计算当前年龄,就要判断,如果现在的月份大约出生的月份,或现在的月份等于出生月份并且现在的日大于出生日,年龄就等于今年的年份减去出生年份,否则就等于这个值再减去一。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)