📜  计划,将Km / hr转换为英里/小时,反之亦然

📅  最后修改于: 2021-05-07 01:24:42             🧑  作者: Mango

给定以km / hr为单位的速度,请将其转换为m / hr,然后将m / hr转换为km / hr。
例子:

Input : 150 (km/hr)
Output : 93.21 
 
Input : 100 (m/hr)
Output : 160.92693917

kph转换为mph的公式为–

1 kilo-metre = 0.621371192 miles

mph到kph的转换公式是–

1 miles = 1.60934 kilo-metre
C++
// Cpp program for conversion of
// kmph to mph and vice versa
#include 
using namespace std;
 
// Function to convert kmph to mph
double kmphTOmph(double kmph)
{
    return 0.6214 * kmph;
}
// Function to convert mph to kmph
double mphTOkmph(double mph)
{
    return mph * 1.60934;
}
 
// Driver code to check the above function
int main()
{
    double kmph = 150;
    double mph = 100;
    cout << "the speed in mph is " << kmphTOmph(kmph) << endl;
    cout << "the speed in kmph is " << mphTOkmph(mph);
 
    return 0;
}


Java
// Java program for the conversion
// kmph to mph and vice versa
import java.io.*;
class GFG {
 
    // Function to convert kmph to mph
    static double kmphTOmph(double kmph)
    {
        return 0.6214 * kmph;
    }
 
    // Function to convert mph to kmph
    static double mphTOkmph(double mph)
    {
        return mph * 1.60934;
    }
    // Driver code to check the above function
    public static void main(String[] args)
    {
        double kmph = 150;
        double mph = 100;
        System.out.println("speed in miles/hr is " + kmphTOmph(kmph));
        System.out.println("speed in km/hr is " + mphTOkmph(mph));
    }
}


Python
# Python program for the conversion
# kmph to mph and vice versa
 
# Function to convert kmph to mph
def kmphTOmph(kmph):
    mph = 0.6214 * kmph
    return mph
 
# Function to convert mph to kmph   
def mphTOkmph(mph):
    kmph =(float)(mph * 1.60934)
    return kmph
 
 
kmph = 150
mph = 100
print "speed in miles / hr is ", kmphTOmph(kmph)
 
print "speed in km / hr is ", mphTOkmph(mph)


C#
// C# program for the conversion
// kmph to mph and vice versa
using System;
 
class GFG {
 
    // Function to convert kmph to mph
    static double kmphTOmph(double kmph)
    {
        return 0.6214 * kmph;
    }
 
    // Function to convert mph to kmph
    static double mphTOkmph(double mph)
    {
        return mph * 1.60934;
    }
 
    // Driver code to check the above function
    public static void Main()
    {
        double kmph = 150;
        double mph = 100;
        Console.WriteLine("speed in miles/hr is " + kmphTOmph(kmph));
        Console.WriteLine("speed in km/hr is " + mphTOkmph(mph));
    }
}
 
// This code is contributed by vt_m


PHP


Javascript


输出:

speed in miles/hr is  93.21
speed in km/hr is  160.934