如果输入以公里/小时为单位,则将其转换为英里/小时,否则输入将以英里/小时为单位,将其转换为公里/小时。有一些公式可用于此转换。
转换公式-
1 kilo-metre = 0.621371 miles 1 miles = 1.60934 Kilo-meter
Input-: kmph= 50.00 Mph = 10.00 Output-: speed in m/ph is 31.07 speed in km/ph is 16.0934
Start Step 1 -> Declare function to将km / ph转换为m / ph- double km_mph(double km) return 0.6214 * km step 2 -> Declare function to convert m/ph to km/ph double m_km(double m_ph) return m_ph * 1.60934 step 3 -> In main() declare variable as double kmph = 50 and double mph = 10 print km_mph(kmph) print m_km(mph) Stop
#include <bits/stdc++.h> using namespace std; //将km / ph转换为m / ph- double km_mph(double km){ return 0.6214 * km; } //转换mph为kmph- double m_km(double m_ph){ return m_ph * 1.60934; } int main(){ double kmph = 50.00; double mph = 10.00; cout << "speed in m/ph is " << km_mph(kmph) << endl; cout << "speed in km/ph is " << m_km(mph); return 0; }
输出结果
speed in m/ph is 31.07 speed in km/ph is 16.0934