📌  相关文章
📜  当两个项目以相同的价格和相同的百分比损益出售时的损失

📅  最后修改于: 2021-04-21 22:26:08             🧑  作者: Mango

给定售价,即两个项目的“ SP” 。一种以“ P%”利润出售,另一种以“ P%”亏损出售。任务是找出整体损失。
例子:

Input: SP = 2400, P = 30%  
Output: Loss = 474.725

Input: SP = 5000, P = 10%
Output: Loss = 101.01

方法:

以上公式如何运作?
营利项目:
通过售价(100 + P),我们可以获得P利润。
通过销售价格SP,我们可以获得SP *(P /(100 + P))利润
对于亏损项目:
以售价(100 – P),我们得到P损失。
使用销售价格SP,我们得到SP *(P /(100 – P))损失
净亏损=总亏损–总利润
= SP *(P /(100 – P))– SP *(P /(100 + P))
=(SP * P * P * 2)/(100 * 100 – P * P)
注意:仅当两个项目的成本价格不同时,以上公式才适用。如果两个项目的CP相同,则在这种情况下, “没有利润就没有损失”。
下面是上述方法的实现

C++
// C++ implementation of above approach.
#include 
using namespace std;
 
// Function that will
// find loss
void Loss(int SP, int P)
{
 
    float loss = 0;
 
    loss = (2 * P * P * SP) / float(100 * 100 - P * P);
 
    cout << "Loss = " << loss;
}
 
// Driver Code
int main()
{
    int SP = 2400, P = 30;
 
    // Calling Function
    Loss(SP, P);
 
    return 0;
}


Java
// Java implementation of above approach.
class GFG
{
 
// Function that will
// find loss
static void Loss(int SP, int P)
{
 
    float loss = 0;
 
    loss = (float)(2 * P * P * SP) / (100 * 100 - P * P);
 
    System.out.println("Loss = " + loss);
}
 
// Driver Code
public static void main(String[] args)
{
    int SP = 2400, P = 30;
 
    // Calling Function
    Loss(SP, P);
}
}
 
// This code has been contributed by 29AjayKumar


Python3
# Python3 implementation of above approach.
 
# Function that will find loss
def Loss(SP, P):
     
    loss = 0
    loss = ((2 * P * P * SP) /
            (100 * 100 - P * P))
    print("Loss =", round(loss, 3))
 
# Driver Code
if __name__ == "__main__":
 
    SP, P = 2400, 30
 
    # Calling Function
    Loss(SP, P)
 
# This code is contributed by Rituraj Jain


C#
// C# implementation of above approach.
class GFG
{
 
// Function that will
// find loss
static void Loss(int SP, int P)
{
 
    double loss = 0;
 
    loss = (double)(2 * P * P * SP) / (100 * 100 - P * P);
 
    System.Console.WriteLine("Loss = " +
                            System.Math.Round(loss,3));
}
 
// Driver Code
static void Main()
{
    int SP = 2400, P = 30;
 
    // Calling Function
    Loss(SP, P);
}
}
 
// This code has been contributed by mits


PHP


Javascript


输出:
Loss = 474.725