📜  查找在给定混合物中要达到目标比例所要添加的量

📅  最后修改于: 2021-05-25 22:01:07             🧑  作者: Mango

您将得到一个X升的容器,其中装有葡萄酒和水的混合物。该混合物中包含W%的水。必须添加多少升水才能使水的比例达到Y%?
输入分别包含3个整数X,W和Y。
输出应为浮点格式,最多2个小数点。
例子:

下面是上述方法的实现:

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


输出:
Water to be added = 25.00