#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,d,m,n,t,y,x,o,u;
printf("请输入两个四位数且每个数前两位大于0小于24后两位大于0小于60:\n");
scanf("%2d%2d%2d%2d",&a,&b,&c,&d);
if((a>=0&&a<24)&&(b>=0&&b<60)&&(c>=0&&c<24)&&(d>=0&&d<60))
{
if((a>=c&&b>=d)||(a<c&&b<d))
{m=fabs(a-c);
n=fabs(b-d);
printf("时间差=%2d小时%2d分",m,n);}
else if(a>c&&b<d)
{ t=fabs(a-c)-1;
y=(60-d)+b;
printf("时间差=%2d小时%2d分",t,y);}
else if(a=c&&b<d)
{u=d-b;
printf("时间差=0小时%2d分",u);}
else
{x=fabs(a-c)-1;
o=(60-b)+d;
printf("时间差=%2d%小时%2d分",x,o);}
}
else
printf("你TM在逗我,请正确输入!!\n");
}
但是注意if后面有几个语句的话用要{}!!!
时间: 2024-11-08 22:31:07