VOOZH about

URL: https://www.geeksforgeeks.org/dsa/calculate-speed-distance-time/

⇱ Calculate speed, distance and time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Calculate speed, distance and time

Last Updated : 17 Feb, 2023

When an object moves in a straight line at a steady speed, we can calculate its speed if we know how far it travels and how long it takes. This equation shows the relationship between speed, distance travelled and time taken: 
Speed is distance divided by the time taken. 
For example, a car travels 30 kilometres in 2 hours. 
Its speed is 30 ÷ 2 = 15km/hr. 

Formula used : 

Distance = Speed * Time
Time = Distance / Speed
Speed = Distance / Time

Examples: 

Input : distance(km) : 48.5 time(hr) : 2.6
Output : Speed(km / hr) : 18.653846153

Input : speed(km / hr) : 46.0 time(hr) : 3.2
Output : Distance(km) : 147.2

Input : distance(km) : 48.5 speed(km / hr) : 46.0
Output : Time(hr) : 1.0543

Output
 Distance(km) : 45.9
 Time(hr) : 2
 The calculated Speed(km / hr) is : 22.95

 Time(hr) : 2.5
 Speed(km / hr) : 62.9
 The calculated Distance(km) : 157.25

 Distance(km) : 48
 Speed(km / hr) : 4.5
 The calculated Time(hr) : 10.6667

Time Complexity: O(1) 
Auxiliary Space: O(1)

Comment