# 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

**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:

- Speed of boat in still water from speed of stream and times taken
- Calculate speed, distance and time
- Speed of boat upstream and downstream
- Program to convert speed in km/hr to m/sec and vice versa
- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Program to find the common ratio of three numbers
- Find if it is possible to get a ratio from given ranges of costs and quantities
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Program to find the count of coins of each type from the given ratio
- Program to find the time after K minutes from given time
- Time difference between expected time and given time
- Find a time for which angle between hour and minute hands is given theta
- Changing One Clock Time to Other Time in Minimum Number of Operations
- GRE Arithmetic | Ratio
- Ratio of mth and nth term in an Arithmetic Progression (AP)

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.