C++ 程序将单位为 km/hr 的速度转换成 m/sec,反之亦然


转换公式 −

1 km/hr = 5/18 m/sec or 0.277778 m/sec
1 m/sec = 18/5 km/hr or 3.6 km/hr

实例

Input-: km = 60.00
   mk = 70.00
Output-: speed in meter per second = 16.6667
   speed in km per hour = 252

算法

Start
Step 1 -> Declare function to convert km/hr into m/sec
   float km_m(float km)
      return (0.277778 * km)
Step 2 -> Declare function to convert m/sec into km/hr
   float m_km(float mk)
      return (3.6 * mk)
step 3 -> In main()
   declare variable as float km = 60.0 and float mk = 70.0
   Print km_m(km)
   Print m_km(mk);
Stop

实例

#include <bits/stdc++.h>
using namespace std;
//function to convert km/hr into m/sec
float km_m(float km){
   return (0.277778 * km);
}
//function to convert m/sec into km/hr
   float m_km(float mk){
      return (3.6 * mk);
}
int main(){
   float km = 60.0;
   float mk = 70.0;
   cout << "speed in meter per second = " << km_m(km)<<endl<< " speed in km per hour = " << m_km(mk);
   return 0;
}

输出

speed in meter per second = 16.6667
speed in km per hour = 252

更新时间:2019-09-23

630 次查看

开启你的 职业生涯

通过完成课程获得认证

开始
广告