Program to convert speed in km/hr to m/sec and vice versa in C++

C++Server Side ProgrammingProgramming

Conversion Formulas −

1 km/hr = 5/18 m/sec or 0.277778 m/sec
1 m/sec = 18/5 km/hr or 3.6 km/hr

Example

Input-: km = 60.00
   mk = 70.00
Output-: speed in meter per second = 16.6667
   speed in km per hour = 252

Algorithm

Start
Step 1 -> Declare function to convert km/hr into m/sec
   float km_m(float km)
      return (0.277778 * km)
Step 2 -> Declare function to convert m/sec into km/hr
   float m_km(float mk)
      return (3.6 * mk)
step 3 -> In main()
   declare variable as float km = 60.0 and float mk = 70.0
   Print km_m(km)
   Print m_km(mk);
Stop

Example

#include <bits/stdc++.h>
using namespace std;
//function to convert km/hr into m/sec
float km_m(float km){
   return (0.277778 * km);
}
//function to convert m/sec into km/hr
   float m_km(float mk){
      return (3.6 * mk);
}
int main(){
   float km = 60.0;
   float mk = 70.0;
   cout << "speed in meter per second = " << km_m(km)<<endl<< " speed in km per hour = " << m_km(mk);
   return 0;
}

Output

speed in meter per second = 16.6667
speed in km per hour = 252
raja
Published on 23-Sep-2019 14:29:32
Advertisements