# Speed of boat in still water from speed of stream and times taken

Write a program to determine speed of the boat in still water(B) given the speed of the stream(S in km/hr), the time taken (for same point) by the boat upstream(T1 in hr) and downstream(T2 in hr).

**Examples:**

Input : T1 = 4, T2 = 2, S = 5 Output : B = 15 Input : T1 = 6, T2 = 1, S = 7 Output : B = 9.8

Prerequisite : Speed of boat upstream and downstream

Speed of boat in still water can be computed using below formula.

**B = S*((T1 + T2) / (T1 – T2))**

**How does this formula work?**

Since the point is same, distance traveled during upstream should be same as downstream.

Therefore,

(B – S) * T1 = (B + S) * T2

B(T1 – T2) = S*(T1 + T2)

B = S*(T1 + T2)/(T1 – T2)

## C++

`// CPP program to find speed of boat in still water ` `// from speed of stream and times taken in downsteam ` `// and upstream ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to calculate the speed of boat in still water ` `float` `still_water_speed(` `float` `S, ` `float` `T1, ` `float` `T2) ` `{ ` ` ` `return` `(S * (T1 + T2) / (T1 - T2)); ` `} ` ` ` `int` `main() ` `{ ` ` ` `float` `S = 7, T1 = 6, T2 = 1; ` ` ` `cout << ` `"The speed of boat in still water = "` `<< ` ` ` `still_water_speed(S, T1, T2)<<` `" km/ hr "` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find speed of boat in still water ` `// from speed of stream and times taken in downsteam ` `// and upstream ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to calculate the ` ` ` `// speed of boat in still water ` ` ` `static` `float` `still_water_speed(` `float` `S, ` `float` `T1, ` `float` `T2) ` ` ` `{ ` ` ` `return` `(S * (T1 + T2) / (T1 - T2)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `float` `S = ` `7` `, T1 = ` `6` `, T2 = ` `1` `; ` ` ` `System.out.println(` `"The speed of boat in still water = "` `+ ` ` ` `still_water_speed(S, T1, T2)+` `" km/ hr "` `); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find speed of boat ` `# in still water from speed of stream and ` `# times taken in downsteam and upstream ` ` ` `# Function to calculate the ` `# speed of boat in still water ` `def` `still_water_speed(S, T1, T2): ` ` ` `return` `(S ` `*` `(T1 ` `+` `T2) ` `/` `(T1 ` `-` `T2)) ` ` ` `# Driver code ` `S ` `=` `7` `; T1 ` `=` `6` `; T2 ` `=` `1` `print` `(` `"The speed of boat in still water = "` `, ` ` ` `still_water_speed(S, T1, T2), ` `" km/ hr "` `) ` ` ` `# This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find speed of boat ` `// in still water from speed of stream ` `// and times taken in downsteam ` `// and upstream ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to calculate the ` ` ` `// speed of boat in still water ` ` ` `static` `float` `still_water_speed(` `float` `S, ` `float` `T1, ` ` ` `float` `T2) ` ` ` `{ ` ` ` `return` `(S * (T1 + T2) / (T1 - T2)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `float` `S = 7, T1 = 6, T2 = 1; ` ` ` `Console.WriteLine(` `"The speed of boat in still water = "` `+ ` ` ` `still_water_speed(S, T1, T2) + ` `" km/ hr "` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?PHP ` `// PHP program to find speed of ` `// boat in still water from speed ` `// of stream and times taken in ` `// downsteam and upstream ` ` ` `// Function to calculate the speed ` `// of boat in still water ` `function` `still_water_speed(` `$S` `, ` `$T1` `, ` `$T2` `) ` `{ ` ` ` `return` `(` `$S` `* (` `$T1` `+ ` `$T2` `) / ` ` ` `(` `$T1` `- ` `$T2` `)); ` `} ` ` ` `// Driver Code ` `$S` `= 7; ` `$T1` `= 6; ` `$T2` `= 1; ` `echo` `(` `"The speed of boat in still water = "` `. ` ` ` `still_water_speed(` `$S` `, ` `$T1` `, ` `$T2` `) . ` ` ` `" km/hr "` `); ` ` ` `// This code is contributed by Smitha ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

The speed of boat in still water = 9.8 km/hr

## Recommended Posts:

- Find speed of man from speed of stream and ratio of time with up and down streams
- Speed of boat upstream and downstream
- Calculate speed, distance and time
- Program to convert speed in km/hr to m/sec and vice versa
- QA - Placement Quizzes | Time Speed Distance | Question 4
- QA - Placement Quizzes | Time Speed Distance | Question 16
- QA - Placement Quizzes | Time Speed Distance | Question 15
- QA - Placement Quizzes | Time Speed Distance | Question 14
- QA - Placement Quizzes | Time Speed Distance | Question 13
- QA - Placement Quizzes | Time Speed Distance | Question 5
- QA - Placement Quizzes | Time Speed Distance | Question 7
- QA - Placement Quizzes | Time Speed Distance | Question 3
- QA - Placement Quizzes | Time Speed Distance | Question 2
- QA - Placement Quizzes | Time Speed Distance | Question 1
- QA - Placement Quizzes | Time Speed Distance | Question 8

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.