# include <stdio.h>
int main(void)
{
int time, distance, speed;
int hour, minute;
printf("Please input the start time (such as 0825): ");
scanf("%d",&time);
printf("Please input the distance(km): ");
scanf("%d",&distance);
printf("Please input the speed(km/h): ");
scanf("%d",&speed);
hour=distance/speed;
minute=distance%speed*60/speed;
minute=minute+time%100;
if(minute>=60)
{
minute=minute-60;
hour++;
}
hour=hour+time/100;
printf("Time of arrival: %d:%02d
",hour,minute);
return 0;
}
没有考虑不能整除的时候,分钟四舍五入的时候,要严谨一定应该考虑,稍微改一下就可以了
下面是考虑了四舍五入的
# include <stdio.h>
int main(void)
{
int time,hour,minute;
float distance, speed,a;//a用来存放分钟的小数部分,方便四舍五入
printf("Please input the start time (such as 0825): ");
scanf("%d",&time);
printf("Please input the distance(km): ");
scanf("%d",&distance);
printf("Please input the speed(km/h): ");
scanf("%d",&speed);
hour=distance/speed;
distance-=hour*speed;
a=distance*60/speed;
minute=a;
a-=minute;
if(a>=0.5)
minute++;
minute=minute+time%100;
if(minute>=60)
{
minute=minute-60;
hour++;
}
hour=hour+time/100;
printf("Time of arrival: %d:%02d
",hour,minute);
return 0;
}