如题所述
#include <stdio.h>
#include <stdlib.h>
main()
{
int hour1,hour2,minute1,minute2,h,m;
printf("Input time one(hour, minute):");
scanf("%d,%d",&hour1,&minute1);
getchar();
printf("Input time two(hour, minute):");
scanf("%d,%d",&hour2,&minute2);
if(hour1>hour2){
h=hour1-hour2;
if(minute1>minute2)
m=minute1-minute2;
else{
m=60+minute1-minute2;
h--;
}
}
else{
h=hour2-hour1;
if(minute1>minute2){
m=60+minute2-minute1;
h--;
}
else
m=minute2-minute1;
}
printf("%d hour %d minute\n",h,m);
system("pause");
}
#include <stdlib.h>
main()
{
int hour1,hour2,minute1,minute2,h,m;
printf("Input time one(hour, minute):");
scanf("%d,%d",&hour1,&minute1);
getchar();
printf("Input time two(hour, minute):");
scanf("%d,%d",&hour2,&minute2);
if(hour1>hour2){
h=hour1-hour2;
if(minute1>minute2)
m=minute1-minute2;
else{
m=60+minute1-minute2;
h--;
}
}
else{
h=hour2-hour1;
if(minute1>minute2){
m=60+minute2-minute1;
h--;
}
else
m=minute2-minute1;
}
printf("%d hour %d minute\n",h,m);
system("pause");
}
程序的运行结果示例1:
Input time one(hour, minute):4,55↙
Input time two(hour, minute):1,25↙
3 hour 30 minute
程序的运行结果示例2:
Input time one(hour, minute):1,56↙
Input time two(hour, minute):3,25↙
1 hour 29 minute
温馨提示:答案为网友推荐,仅供参考
第1个回答 2017-10-07
#include <stdio.h>
void main()
{
int a,b,c,d,t,s1,s2;
scanf("%d:%d",&a,&b);
scanf("%d:%d",&c,&d);
if(a<0||a>24||c<0||c>24||b<0||b>60||d<0||d>60)
printf("Input error!");
else
{
if(a==c) {s1=0;s2=abs(b-d);}
else
{
if(a<c)
{t=a;a=c;c=t;t=b;b=d;d=t;}
if(b<d) {b+=60;a-=1;}
s1=a-c;s2=b-d;
}
printf("%d hour %d minute",s1,s2);
}
}本回答被网友采纳
void main()
{
int a,b,c,d,t,s1,s2;
scanf("%d:%d",&a,&b);
scanf("%d:%d",&c,&d);
if(a<0||a>24||c<0||c>24||b<0||b>60||d<0||d>60)
printf("Input error!");
else
{
if(a==c) {s1=0;s2=abs(b-d);}
else
{
if(a<c)
{t=a;a=c;c=t;t=b;b=d;d=t;}
if(b<d) {b+=60;a-=1;}
s1=a-c;s2=b-d;
}
printf("%d hour %d minute",s1,s2);
}
}本回答被网友采纳