C ++程序将公里/小时转换为英里/小时,反之亦然
如果输入以公里/小时为单位,则将其转换为英里/小时,否则输入将以英里/小时为单位,将其转换为公里/小时。有一些公式可用于此转换。
转换公式-
1 kilo-metre = 0.621371 miles1 miles = 1.60934 Kilo-meter
示例
Input-: kmph= 50.00Mph = 10.00
Output-: speed in m/ph is 31.07
speed in km/ph is 16.0934
算法
StartStep 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.07speed in km/ph is 16.0934
以上是 C ++程序将公里/小时转换为英里/小时,反之亦然 的全部内容, 来源链接: utcz.com/z/335153.html