📜  使用给定的质量和体积找到溶液的浓度

📅  最后修改于: 2021-05-05 00:05:04             🧑  作者: Mango

给定两个值MV代表溶质的质量和溶液的体积,任务是计算溶液的浓度。
例子:

方法:溶液的浓度定义为每升溶液中的溶质质量(克)。
数学上:

因此,为了解决该问题,请按照下列步骤操作:

  1. 使用公式C = 1000 *(M / V)计算溶液的浓度。
  2. 打印结果。

下面是上述方法的实现:

C++
// C++ program to find
// concentration of a solution
// using given Mass and Volume
 
#include 
using namespace std;
 
// Function to calculate
// concentration from the
// given mass of solute and
// volume of a solution
double get_concentration(double mass,
                         double volume)
{
    if (volume == 0)
        return -1;
    else
        return (mass / volume)
               * 1000;
}
 
// Driver Program
int main()
{
    double mass, volume;
    mass = 100.00;
    volume = 500.00;
    cout << get_concentration(mass,
                              volume);
    return 0;
}


Java
// Java program to find concentration
// of a solution using given Mass
// and Volume
class GFG{
 
// Function to calculate
// concentration from the
// given mass of solute and
// volume of a solution
static double get_concentration(double mass,
                                double volume)
{
    if (volume == 0)
        return -1;
    else
        return (mass / volume) * 1000;
}
 
// Driver code
public static void main(String[] args)
{
    double mass, volume;
    mass = 100.00;
    volume = 500.00;
     
    System.out.println(get_concentration(mass,
                                         volume));
}
}
 
// This code is contributed by Ritik Bansal


Python3
# Python3 program to find
# concentration of a solution
# using given Mass and Volume
 
# Function to calculate
# concentration from the
# given mass of solute and
# volume of a solution
def get_concentration(mass, volume):
     
    if (volume == 0):
        return -1;
    else:
        return (mass / volume) * 1000;
 
# Driver code
mass = 100.00;
volume = 500.00;
 
print(get_concentration(mass, volume))
     
# This code is contributed by Pratima Pandey


C#
// C# program to find concentration
// of a solution using given Mass
// and Volume
using System;
class GFG{
 
// Function to calculate
// concentration from the
// given mass of solute and
// volume of a solution
static double get_concentration(double mass,
                                double volume)
{
    if (volume == 0)
        return -1;
    else
        return (mass / volume) * 1000;
}
 
// Driver code
public static void Main()
{
    double mass, volume;
    mass = 100.00;
    volume = 500.00;
     
    Console.Write(get_concentration(mass,
                                    volume));
}
}
 
// This code is contributed by rock_cool


Javascript


输出:
200

时间复杂度: O(1)
辅助空间: O(1)