📜  从给定的利润百分比和成本中查找售价

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

给定成本价

*** QuickLaTeX cannot compile formula:
 

*** Error message:
Error: Nothing to show, formula is empty

利润百分比

*** QuickLaTeX cannot compile formula:
 

*** Error message:
Error: Nothing to show, formula is empty

项目的任务是计算售价。
例子:

Input: CP = 500, Profit% = 20
Output: SP = 600

Input: CP = 720, Profit% = 13
Output: SP = 813.6

方法:

  1. 找到利润百分比的十进制等值,然后用百分比除以100。
  2. 加1可获得单价增加的小数当量。
  3. 将成本价乘积与上述结果相乘得出售价。

下面是上述方法的实现:
程序:

C++
// C++ implementation of above approach
 
#include 
using namespace std;
 
// Function to calculate the Selling Price
float SellingPrice(float CP, float PP)
{
 
    // Decimal Equivalent of Profit Percentage
    float P_decimal = 1 + (PP / 100);
 
    // Find the Selling Price
    float res = P_decimal * CP;
 
    // return the calculated Selling Price
    return res;
}
 
// Driver code
int main()
{
 
    // Get the CP and Profit%
    float C = 720, P = 13;
 
    // Printing the returned value
    cout << SellingPrice(C, P);
 
    return 0;
}


Java
// Java implementation of above approach
 
import java.util.*;
 
class solution
{
 
// Function to calculate the Selling Price
static float SellingPrice(float CP, float PP)
{
 
    // Decimal Equivalent of Profit Percentage
    float P_decimal = 1 + (PP / 100);
 
    // Find the Selling Price
    float res = P_decimal * CP;
 
    // return the calculated Selling Price
    return res;
}
 
// Driver code
public static void main(String args[])
{
 
    // Get the CP and Profit%
    float C = 720, P = 13;
 
    // Printing the returned value
    System.out.println(SellingPrice(C, P));
 
}
 
}


Python3
# Python 3 implementation of
# above approach
 
# Function to calculate the
# Selling Price
def SellingPrice (CP, PP):
     
    # Decimal Equivalent of
    # Profit Percentage
    Pdecimal = 1 + ( PP / 100 )
     
    res = Pdecimal * CP
     
    # return the calculated
    # Selling Price
    return res
 
# Driver code
if __name__ == "__main__" :
 
    # Get the CP and Profit %
    C = 720
    P = 13
     
    # Printing the returned value
    print(SellingPrice(C, P))


C#
// C# implementation of above approach
using System;
 
class GFG
{
 
// calculate Nth term of series
static float SellingPrice(float CP,
                          float PP)
{
    // Decimal Equivalent of
    // Profit Percentage
    float P_decimal = 1 + (PP / 100);
 
    // Find the Selling Price
    float res = P_decimal * CP;
 
    // return the calculated
    // Selling Price
    return res;
}
 
// Driver Code
public static void Main()
{
    // Get the CP Profit%
    float C = 720, P = 13;
 
    // Printing the returned value
    Console.Write(SellingPrice(C,P));
}
}
 
// This code is contributed
// by Sanjit_Prasad


PHP


Javascript


输出:
813.6