# Find amount to be added to achieve target ratio in a given mixture

You are given a container of X liters containing a mixture of wine and water. The mixture contains W% of water in it. How much liters of water must be added to increase the ratio of water to Y%?
Input contains 3 integers X, W and Y respectively.
The output should be in float format up to 2 decimal points.
Examples:

Input : X = 125, W = 20, Y = 25
Output : 8.33 liters
20% of 125 is 25. If we add 8.33 liters, we get 33.33 which is 25% of 133.33.

Input : X = 100, W = 50, Y = 60
Output : 25

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

Let the amount of water to be added be A liters.
So, the new amount of mixture = (X + A) liters
And the amount of water in the mixture = (old amount + A) = ((W % of X ) + A )
Also, the amount of water in the mixture = new percentage of water in new mixture = Y % of (X + A)
Now, we can write the expression as
———————————
Y % of ( X + A) = W % of X + A
———————————-
Since, both denote the amount of water.
On simplifying this expression, we will get

A = [X * (Y – W)] / [100 – Y]

Illustration :
X = 125, W = 20% and Y = 25%;

So, for the given question, the amount of water to be added = (125 * (25 – 20)) / (100 – 25) = 8.33 liters

Below is the implementation of above approach:

## C

 `// C program to find amount of water to ` `// be added to achieve given target ratio. ` `#include ` ` `  `float` `findAmount(``float` `X, ``float` `W, ``float` `Y) ` `{ ` `    ``return` `(X * (Y - W)) / (100 - Y); ` `} ` ` `  `int` `main() ` `{ ` `    ``float` `X = 100, W = 50, Y = 60; ` `    ``printf``(``"Water to be added = %.2f "``,  ` `                 ``findAmount(X, W, Y)); ` `    ``return` `0; ` `}     `

## Java

 `// Java program to find amount of water to ` `// be added to achieve given target ratio. ` ` `  `public` `class` `GFG { ` `     `  `    ``static` `float` `findAmount(``float` `X, ``float` `W, ``float` `Y) ` `    ``{ ` `        ``return` `(X * (Y - W)) / (``100` `- Y); ` `    ``} ` ` `  `     `  `    ``// Driver code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `           ``float` `X = ``100``, W = ``50``, Y = ``60``; ` `           ``System.out.println(``"Water to be added = "``+ findAmount(X, W, Y)); ` ` `  ` `  `    ``} ` `    ``// This code is contributed by ANKITRAI1 ` `} `

## Python3

 `# Python3 program to find amount  ` `# of water to be added to achieve  ` `# given target ratio.  ` `def` `findAmount(X, W, Y): ` `     `  `    ``return` `(X ``*` `(Y ``-` `W) ``/` `(``100` `-` `Y)) ` ` `  `X ``=` `100` `W ``=` `50``; Y ``=` `60` `print``(``"Water to be added"``, ` `       ``findAmount(X, W, Y)) ` ` `  `# This code is contributed ` `# by Shrikant13 `

## C#

 `// C# program to find amount of water to ` `// be added to achieve given target ratio. ` `using` `System; ` `class` `GFG ` `{ ` ` `  `public` `static` `double` `findAmount(``double` `X,  ` `                                ``double` `W,  ` `                                ``double` `Y) ` `{ ` `    ``return` `(X * (Y - W)) / (100 - Y); ` `} ` ` `  `// Driver code ` `public` `static` `void` `Main() ` `{ ` `    ``double` `X = 100, W = 50, Y = 60; ` `    ``Console.WriteLine(``"Water to be added = {0}"``,  ` `                           ``findAmount(X, W, Y)); ` `} ` `} ` ` `  `// This code is contributed by Soumik `

## PHP

 ` `

Output:

```Water to be added = 25.00
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

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.