Program to Convert Km/hr to miles/hr and vice versa

31 May, 2022
Given a speed in km/hr, Convert it to m/hr and m/hr to km/hr. 
Examples: 
Input : 150 (km/hr)
Output : 93.21 
 
Input : 100 (m/hr)
Output : 160.92693917
The conversion formula for kph to mph is – 
1 kilo-meter = 0.621371192 miles
The conversion formula for mph to kph is – 
1 miles = 1.60934 kilo-meter
C++
Java
Python
C#
PHP
Javascript
// Cpp program for conversion of// kmph to mph and vice versa#include <bits/stdc++.h>using namespace std; // Function to convert kmph to mphdouble kmphTOmph(double kmph){    return 0.6214 * kmph;}// Function to convert mph to kmphdouble mphTOkmph(double mph){    return mph * 1.60934;} // Driver code to check the above functionint 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 program for the conversion// kmph to mph and vice versaimport 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 program for the conversion# kmph to mph and vice versa # Function to convert kmph to mphdef 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 = 150mph = 100print "speed in miles / hr is ", kmphTOmph(kmph) print "speed in km / hr is ", mphTOkmph(mph)
// C# program for the conversion// kmph to mph and vice versausing 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// PHP program for conversion of// kmph to mph and vice versa // Function to convert// kmph to mphfunction kmphTOmph($kmph){    return 0.6214 * $kmph;} // Function to convert// mph to kmphfunction mphTOkmph($mph){    return $mph * 1.60934;}     // Driver Code    $kmph = 150;    $mph = 100;    echo "speed in mph is " ,          kmphTOmph($kmph),"\n";    echo "speed in kmph is " ,               mphTOkmph($mph); // This code is contributed by anuj_67.?>
<script> // javascript program for the conversion// kmph to mph and vice versa   // Function to convert kmph to mphfunction kmphTOmph(kmph){     return (0.6214 * kmph);}   // Function to convert mph to kmphfunction mphTOkmph(mph){    return (1.60934 * mph) ;} // Driver Codevar kmph = 150var mph = 100 document.write("speed in miles/hr is " + kmphTOmph(kmph) + "<br>"); document.write("speed in km/hr is " + mphTOkmph(mph));     // This code is contributed by bunnyram19.</script>
Output: 
speed in miles/hr is  93.21
speed in km/hr is  160.934
Time Complexity: O(1), as we are not using any loops or recursion.
Auxiliary Space: O(1), as we are not using any extra space.
vt_m
bunnyram19
adnanirshad158
rohitsingh07052
C Programs
Java Programs
Mathematical
Python Programs
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.