Program to find the speed of man in km/hr, given the speed of stream in km/hr. Assume that the man takes n times (where n > 1) as long to row upstream as to row downstream the river.

Examples:

Input : 5.5 4 Output : speed of man is 9.16667 km/hr Input : 4 3 Output : speed of man is 8 km/hr

**Approach Used :**

Let speed of the man in still water = **x km/hr**

Let speed of the stream = **y km/hr**

Then, speed downstream = **(x + y) km/hr**

speed upstream = **(x – y) km/hr**

Let time taken to travel downstream = **t hr**

Then, time taken to travel upstream = **nt hr**

Distance travelled downstream = **(x + y)t km** ————-(1)

Distance travelled upstream = **(x – y)tn km** ————-(2)

from (1) and (2)

(x + y)t = (x – y)tn

which gives : (x + y) = (x – y)n

which gives : x + y = nx – ny

which gives : nx – x = ny + y

which gives : x(n – 1) = y(n + 1)

which gives :** x = y(n + 1)/(n – 1)**

## C++

`// C++ implementation ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function to return speed of man ` `float` `speed_man(` `float` `y1, ` `int` `n1) ` `{ ` ` ` `// return the speed of man in km/hr ` ` ` `return` `( y1 * (n1 + 1) / (n1 - 1) ); ` ` ` `} ` ` ` `// Driver function ` `int` `main() ` `{ ` ` ` `// y is speed of stream in km/hr ` ` ` `float` `y = 2.3; ` ` ` `int` `n = 6; ` ` ` ` ` `float` `speed = speed_man(y, n); ` ` ` `cout << ` `"speed of man is "` `<< speed ` ` ` `<< ` `" km/hr"` `<< endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Implementation ` `import` `java.lang.*; ` `import` `java.util.*; ` ` ` `public` `class` `GeeksforGeeks { ` ` ` ` ` `// function to return speed of man ` ` ` `static` `float` `speed_man(` `float` `y1, ` `int` `n1) ` ` ` `{ ` ` ` `// x is speed of man ` ` ` `return` `( y1 * (n1 + ` `1` `) / (n1 - ` `1` `) ); ` ` ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `// y is speed of stream in km/hr ` ` ` `float` `y = ` `2` `.3f; ` ` ` `int` `n = ` `6` `; ` ` ` `float` `speed = speed_man(y, n); ` ` ` ` ` `System.out.println(` `"speed of man is "` ` ` `+ speed + ` `" km/hr"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

` ` `# Python3 implementation to find ` `# the speed of man in km/hr ` ` ` `# Function to return speed of man ` `def` `speed_man(y1, n1): ` ` ` ` ` `# return the speed of man in km/hr ` ` ` `return` `(y1 ` `*` `(n1 ` `+` `1` `) ` `/` `(n1 ` `-` `1` `)) ` ` ` `# Driver Code ` ` ` `# y is speed of stream in km/hr ` `y ` `=` `2.3` `; n ` `=` `6` ` ` `speed ` `=` `speed_man(y, n) ` `print` `(` `"speed of man is "` `, ` ` ` `"%.2f"` `%` `speed, ` `" km/hr"` `) ` ` ` `# This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## C#

`// C# Implementation ` `using` `System; ` ` ` `public` `class` `GFG { ` ` ` ` ` `// function to return speed of man ` ` ` `static` `float` `speed_man(` `float` `y1, ` `int` `n1) ` ` ` `{ ` ` ` ` ` `// x is speed of man ` ` ` `return` `( y1 * (n1 + 1) / (n1 - 1) ); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `// y is speed of stream in km/hr ` ` ` `float` `y = 2.3f; ` ` ` `int` `n = 6; ` ` ` `float` `speed = speed_man(y, n); ` ` ` ` ` `Console.WriteLine(` `"speed of man is "` ` ` `+ speed + ` `" km/hr"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation to find ` `// the speed of man in km/hr ` ` ` `// function to return ` `// speed of man ` `function` `speed_man(` `$y1` `, ` `$n1` `) ` `{ ` ` ` ` ` `// return the speed of ` ` ` `// man in km/hr ` ` ` `return` `(` `$y1` `* (` `$n1` `+ 1) / ` ` ` `(` `$n1` `- 1) ); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `// y is speed of ` ` ` `// stream in km/hr ` ` ` `$y` `= 2.3; ` ` ` `$n` `= 6; ` ` ` ` ` `$speed` `= speed_man(` `$y` `, ` `$n` `); ` ` ` `echo` `"speed of man is "` `, ` `$speed` ` ` `, ` `" km/hr"` `; ` ` ` `// This code is contributed by anuj_67. ` `?> ` |

*chevron_right*

*filter_none*

Output:

speed of man is 3.22 km/hr

## Recommended Posts:

- GRE Arithmetic | Ratio
- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Minimum time required to complete a work by N persons together
- Find Selling Price from given Profit Percentage and Cost
- Program to find the Break Even Point
- Program to find the number of men initially
- Find number of candidates in the Exam
- Program to find the last digit of X in base Y
- Aptitude | Simplification and Approximation | Question 1
- Aptitude | Simplification and Approximation | Question 2
- Aptitude | Simplification and Approximation | Question 3
- Aptitude | Simplification and Approximation | Question 4
- Aptitude | Simplification and Approximation | Question 5
- Aptitude | Simplification and Approximation | Question 6
- Aptitude | Simplification and Approximation | Question 7
- Aptitude | Simplification and Approximation | Question 8
- Aptitude | Simplification and Approximation | Question 9
- Aptitude | Simplification and Approximation | Question 10
- Aptitude | Simplification and Approximation | Question 11
- Aptitude | Simplification and Approximation | Question 12

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.