题目
做一道C语言程序设计的题,十万火急!
已知列车出发时间(输入格式为4位数,如0825),
甲乙两地距离(单位是千米),
速度(km/h).求列车到底乙地的时间,
要求格式为(小时:分钟
已知列车出发时间(输入格式为4位数,如0825),
甲乙两地距离(单位是千米),
速度(km/h).求列车到底乙地的时间,
要求格式为(小时:分钟
提问时间:2020-10-10
答案
# 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;
}
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;
}
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;
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1英语翻译:电视声音很大,请调小一点.
- 2英语翻译
- 3把0.8改写成用百分之一为计数单位的数是_.
- 4一本故事书,宣宣第一天看了全书的7分之2,第二天看了剩下的3分之1,第二天看了全书的多少
- 5when the shoe is on the other foot?在具体语境中有什么意思
- 6妈妈买回一箱橘子,连箱重20千克.吃去橘子一半后,连箱重11千克,这箱橘子净重多少千克?用方程解
- 7弹簧测力计的原理是_.
- 8The Dog and His Shadow
- 9A、B、C是球面上三点,已知弦(连接球面上两点的线段)AB=18cm,BC=24cm,AC=30cm,平面ABC与球心的距离恰好为球半径的一半,求球的表面积和体积.
- 10人教版语文书上《小石潭记》课后练习题题目和答案给一下.书上原题.
热门考点
- 1is duty the on policeman怎么连词成句
- 2sin^2θ·cosθ 与sinθ·cos^2θ 极值应该怎么求?
- 3如图,在△ABC中,∠A=20°,D在AB上,AD=DC,∠ACD:∠BCD=2:3,求:∠ABC的度数.
- 4i said that joining an english club is a good way should aways be.问为什么joining加ing
- 5已知直角三角形斜边上的中线长为1,周长为2+6,则这个三角形的面积为( ) A.12 B.1 C.2 D.6
- 6The river teems with all kinds of fish in summer
- 7两个质数和是30,积是221,他们的差是几?
- 8英勇果断的近义词是什么?要四字的
- 9一条路,第一天修了250米,第二天修了全长的2/5,还剩1/10未修,这条路有多长,
- 10有50根土豆条,吃了十二分之一根,问:还剩几分之几根?