就为这个。。。
程序填空,不要改变与输入输出有关的语句。
输入2个整数time1和time2,表示火车的出发时间和到达时间,计算并输出旅途时间。有效的时间范围是0000到2359,不考虑出发时间晚于到达时间的情况。例:
输入
713 1411(出发7:10,到达14:11)
输出
The train journey time is 6 hrs 58 mins.
#include <stdio.h>
int main( )
{
int time1, time2, hours, mins;
scanf("%d%d", &time1, &time2);
/*---------*/
printf("The train journey time is %d hrs %d mins.\n", hours, mins);
}
參考答案:int main( )
{
int time1, time2, hours, mins;
scanf("%d%d", &time1, &time2);
hours = time2/100 - time1/100;
mins = time2%100 - time1%100;
if(mins < 0) {
hours--;
mins+=60;
}
if(hours < 0) hours+=24;
printf("The train journey time is %d hrs %d mins.\n", hours, mins);
}
/是除
%是取余