# Find amount of water wasted after filling the tank

Given the volume V of a tank in liter. There is a pump which is filling the tank at speed of M liter per minute. There is a leakage at the bottom of the tank which wasting water at speed N liter per minute. Given N is less than M. The task is to calculate how much amount of water will be wasted if leakage is seen after filling the full tank.

Examples:

```Input : V = 700, M = 10, N = 3
Output : 300

Input : V = 1000, M = 100, N = 50
Output : 1000
```

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

Approach : Given the speed of filling pump is M liter per minute. So, the amount of water filled in one minute is M Liter. Also, N litres of water is wasted in a minute. Therefore after one minute the amount of water in the tank will be (M – N). Hence total time taken to fill the tank with leakage will be V / (M-N).

Therefore the amount of wasted water will be (V / (M-N)) * N.

Below is the implementation of the above approach:

## C++

 `// C++ program to find the volume of water wasted ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to calculate amount of wasted water ` `double` `wastedWater(``double` `V, ``double` `M, ``double` `N) ` `{ ` `    ``double` `wasted_amt, amt_per_min, time_to_fill; ` ` `  `    ``// filled amount of water in one minute ` `    ``amt_per_min = M - N; ` ` `  `    ``// total time taken to fill the tank ` `    ``// because of leakage ` `    ``time_to_fill = V / amt_per_min; ` ` `  `    ``// wasted amount of water ` `    ``wasted_amt = N * time_to_fill; ` ` `  `    ``return` `wasted_amt; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``double` `V, M, N; ` `    ``V = 700; ` `    ``M = 10; ` `    ``N = 3; ` `    ``cout << wastedWater(V, M, N) << endl; ` ` `  `    ``V = 1000; ` `    ``M = 100; ` `    ``N = 50; ` `    ``cout << wastedWater(V, M, N) << endl; ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java program to find the  ` `// volume of water wasted ` `class` `GFG ` `{ ` `     `  `// Function to calculate amount of wasted water ` `static` `double` `wastedWater(``double` `V, ``double` `M, ``double` `N) ` `{ ` `    ``double` `wasted_amt, amt_per_min, time_to_fill; ` ` `  `    ``// filled amount of water in one minute ` `    ``amt_per_min = M - N; ` ` `  `    ``// total time taken to fill the tank ` `    ``// because of leakage ` `    ``time_to_fill = V / amt_per_min; ` ` `  `    ``// wasted amount of water ` `    ``wasted_amt = N * time_to_fill; ` ` `  `    ``return` `wasted_amt; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``double` `V, M, N; ` `    ``V = ``700``; ` `    ``M = ``10``; ` `    ``N = ``3``; ` `    ``System.out.println(wastedWater(V, M, N)) ; ` ` `  `    ``V = ``1000``; ` `    ``M = ``100``; ` `    ``N = ``50``; ` `    ``System.out.println(wastedWater(V, M, N)); ` `} ` `} ` ` `  `// This Code is Contributed by Code_Mech. `

## Python3

 `# Python3 program to find the volume  ` `# of water wasted ` ` `  `# Function to calculate amount  ` `# of wasted water ` `def` `wastedWater(V, M, N): ` ` `  `    ``# filled amount of water in one minute ` `    ``amt_per_min ``=` `M ``-` `N ` ` `  `    ``# total time taken to fill the tank ` `    ``# because of leakage ` `    ``time_to_fill ``=` `V ``/` `amt_per_min ` ` `  `    ``# wasted amount of water ` `    ``wasted_amt ``=` `N ``*` `time_to_fill ` ` `  `    ``return` `wasted_amt ` ` `  `# Driver code ` `V ``=` `700` `M ``=` `10` `N ``=` `3` `print``(wastedWater(V, M, N)) ` ` `  `V ``=` `1000` `M ``=` `100` `N ``=` `50` `print``(wastedWater(V, M, N)) ` ` `  `# This code is contributed by Shrikant13 `

## C#

 `// C# program to find the  ` `// volume of water wasted ` `using` `System; ` ` `  `class` `GFG ` `{ ` `         `  `    ``// Function to calculate amount of wasted water ` `    ``static` `double` `wastedWater(``double` `V, ``double` `M, ``double` `N) ` `    ``{ ` `        ``double` `wasted_amt, amt_per_min, time_to_fill; ` `     `  `        ``// filled amount of water in one minute ` `        ``amt_per_min = M - N; ` `     `  `        ``// total time taken to fill the tank ` `        ``// because of leakage ` `        ``time_to_fill = V / amt_per_min; ` `     `  `        ``// wasted amount of water ` `        ``wasted_amt = N * time_to_fill; ` `     `  `        ``return` `wasted_amt; ` `    ``} ` `     `  `    ``// Driver code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``double` `V, M, N; ` `        ``V = 700; ` `        ``M = 10; ` `        ``N = 3; ` `        ``Console.WriteLine(wastedWater(V, M, N)) ; ` `     `  `        ``V = 1000; ` `        ``M = 100; ` `        ``N = 50; ` `        ``Console.WriteLine(wastedWater(V, M, N)); ` `    ``} ` `} ` ` `  `// This Code is Contributed by ihritik `

## PHP

 ` `

Output:

```300
1000
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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 : shrikanth13, Code_Mech, ihritik

Article Tags :
Practice Tags :

Be the First to upvote.

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