# Speed of boat upstream and downstream

Write a program to find the speed of boat upstream and downstream. In order to calculate the speed of the boat upstream and downstream, we should know the speed of the boat in still water(**B**) and speed of the stream (**S**)

Examples:

Input : B = 10, S = 4 Output : Speed Downstream = 14 km/hr Speed Upstream = 6 km/hr Input : B = 12, S = 5 Output : Speed Downstream = 17 km/hr Speed Upstream = 7 km/hr

**Approach : ** The direction along the stream is called downstream and the direction opposite the stream is called upstream . So in case of downstream the speeds will be added, while in case of upstream the speeds will be subtracted .

The speed of boat downstream is equal to the sum of the speed of the boat in still water and speed of the stream .

The speed of boat upstream is equal to the difference of the speed of the boat in still water and speed of the stream .Hence :

Speed Downstream = B + S km/hr

Speed Upstream = B – S km/hr

## C++

`// CPP program to find upstream and ` `// downstream speeds of a boat. ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to calculate the ` `// speed of boat downstream ` `int` `Downstream(` `int` `b, ` `int` `s) ` `{ ` ` ` `return` `(b + s); ` `} ` ` ` `// Function to calculate the ` `// speed of boat upstream ` `int` `Upstream(` `int` `b, ` `int` `s) ` `{ ` ` ` `return` `(b - s); ` `} ` ` ` `// Driver function ` `int` `main() ` `{ ` ` ` `// Speed of the boat in still water(B) ` ` ` `// and speed of the stream (S) in km/hr ` ` ` `int` `B = 10, S = 4; ` ` ` `cout << ` `"Speed Downstream = "` `<< Downstream(B, S) ` ` ` `<< ` `" km/hr\n"` `<< ` `"Speed Upstream = "` `<< ` ` ` `Upstream(B, S) << ` `" km/hr"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find upstream and ` `// downstream speeds of a boat. ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to calculate the ` ` ` `// speed of boat downstream ` ` ` `static` `int` `Downstream(` `int` `b, ` `int` `s) ` ` ` `{ ` ` ` `return` `(b + s); ` ` ` `} ` ` ` ` ` `// Function to calculate the ` ` ` `// speed of boat upstream ` ` ` `static` `int` `Upstream(` `int` `b, ` `int` `s) ` ` ` `{ ` ` ` `return` `(b - s); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `// Speed of the boat in still water(B) ` ` ` `// and speed of the stream (S) in km/hr ` ` ` `int` `B = ` `10` `, S = ` `4` `; ` ` ` `System.out.println (` `"Speed Downstream = "` `+ Downstream(B, S) ` ` ` `+ ` `" km/hr\n"` `+ ` `"Speed Upstream = "` `+ ` ` ` `Upstream(B, S) + ` `" km/hr"` `); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find upstream ` `# and downstream speeds of a boat. ` ` ` `# Function to calculate the ` `#speed of boat downstream ` `def` `Downstream(b, s): ` ` ` `return` `(b ` `+` `s) ` ` ` `# Function to calculate the ` `# speed of boat upstream ` `def` `Upstream(b, s): ` ` ` `return` `(b ` `-` `s) ` ` ` `# Driver Code ` ` ` `# Speed of the boat in still water(B) ` `# and speed of the stream (S) in km/hr ` `B ` `=` `10` `; S ` `=` `4` `print` `(` `"Speed Downstream = "` `, Downstream(B, S), ` `" km/hr"` `, ` ` ` `"\nSpeed Upstream = "` `, Upstream(B, S), ` `" km/hr"` `) ` ` ` `# This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find upstream and ` `// downstream speeds of a boat. ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to calculate the ` ` ` `// speed of boat downstream ` ` ` `static` `int` `Downstream(` `int` `b, ` `int` `s) ` ` ` `{ ` ` ` `return` `(b + s); ` ` ` `} ` ` ` ` ` `// Function to calculate the ` ` ` `// speed of boat upstream ` ` ` `static` `int` `Upstream(` `int` `b, ` `int` `s) ` ` ` `{ ` ` ` `return` `(b - s); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `// Speed of the boat in still water(B) ` ` ` `// and speed of the stream (S) in km/hr ` ` ` `int` `B = 10, S = 4; ` ` ` `Console.WriteLine(` `"Speed Downstream = "` `+ Downstream(B, S) + ` ` ` `" km/hr\n"` `+ ` `"Speed Upstream = "` `+ ` ` ` `Upstream(B, S) + ` `" km/hr"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

Output:

Speed Downstream = 14 km/hr Speed Upstream = 6 km/hr

## Recommended Posts:

- Speed of boat in still water from speed of stream and times taken
- Find speed of man from speed of stream and ratio of time with up and down streams
- Distance between two points travelled by a boat
- 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 5
- QA - Placement Quizzes | Time Speed Distance | Question 11
- QA - Placement Quizzes | Time Speed Distance | Question 10
- QA - Placement Quizzes | Time Speed Distance | Question 8
- QA - Placement Quizzes | Time Speed Distance | Question 7
- QA - Placement Quizzes | Time Speed Distance | Question 1
- QA - Placement Quizzes | Time Speed Distance | Question 2
- QA - Placement Quizzes | Time Speed Distance | Question 3
- QA - Placement Quizzes | Time Speed Distance | Question 4
- QA - Placement Quizzes | Time Speed Distance | Question 6

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.