Program to Convert Km/hr to miles/hr and vice versa
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-metre = 0.621371192 miles
The conversion formula for mph to kph is –
1 miles = 1.60934 kilo-metre
C++
// Cpp program for conversion of // kmph to mph and vice versa #include <bits/stdc++.h> 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; } |
chevron_right
filter_none
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)); } } |
chevron_right
filter_none
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 = 100print "speed in miles / hr is ", kmphTOmph(kmph) print "speed in km / hr is ", mphTOkmph(mph) |
chevron_right
filter_none
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 |
chevron_right
filter_none
PHP
<?php // PHP program for conversion of // kmph to mph and vice versa // Function to convert // kmph to mph function kmphTOmph($kmph) { return 0.6214 * $kmph; } // Function to convert // mph to kmph function 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. ?> |
chevron_right
filter_none
Output:
speed in miles/hr is 93.21 speed in km/hr is 160.934
Recommended Posts:
- Program to convert speed in km/hr to m/sec and vice versa
- Convert from any base to decimal and vice versa
- Python | Convert string to DateTime and vice-versa
- C Program for Lower Case to Uppercase and vice-versa in a file
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Python program to convert POS to SOP
- Program to convert a given number to words
- Program to convert Array to Set in Java
- Program to Convert Set to List in Java
- Program to convert a given number to words | Set 2
- Program to convert a Map to a Stream in Java
- Program to Convert Radian to Degree
- Program to convert Array to List in Java
- Python program to convert floating to binary
- Program to convert centimeter into meter and kilometer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m



