# Find speed of man from speed of stream and ratio of time with up and down streams

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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 ` `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; ` `} `

## 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"``); ` `    ``} ` `} `

## 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. `

## 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. `

## PHP

 ` `

Output:

```speed of man is 3.22 km/hr
```

My Personal Notes arrow_drop_up In love with a semicolon because sometimes i miss it so badly)

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.

Improved By : vt_m

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.