How do you calculate selling price when selling price and profit percentage is given?

Improve Article

Save Article

  • Read
  • Discuss
  • Improve Article

    Save Article

    Given the Selling Price(SP) and percentage profit or loss of a product. The task is to Calculate the cost price(CP) of the product.
    Examples: 
     

    Input:  SP = 1020, Profit Percentage = 20
    Output: CP = 850
    
    Input: SP = 900, Loss Percentage = 10
    Output:  CP = 1000

    Approach: 
     

    • Formula to calculate cost price if selling price and profit percentage are given:
       

    CP = ( SP * 100 ) / ( 100 + percentage profit).

    • Formula to calculate cost price if selling price and loss percentage are given:
       

    CP = ( SP * 100 ) / ( 100 – percentage loss ).

    Below is the required implementation: 
     

    C++

    #include <iostream>

    using namespace std;

    float CPwithProfit(int sellingPrice, int profit)

    {

        float costPrice;

        costPrice = (sellingPrice * 100.0) / (100 + profit);

        return costPrice;

    }

    float CPwithLoss(int sellingPrice, int loss)

    {

        float costPrice;

        costPrice = (sellingPrice * 100.0) / (100 - loss);

        return costPrice;

    }

    int main()

    {

        int SP, profit, loss;

        SP = 1020;

        profit = 20;

        cout << "Cost Price = " << CPwithProfit(SP, profit) << endl;

        SP = 900;

        loss = 10;

        cout << "Cost Price = " << CPwithLoss(SP, loss) << endl;

        SP = 42039;

        profit = 8;

        cout << "Cost Price = " << CPwithProfit(SP, profit) << endl;

        return 0;

    }

    Java

    import java.util.*;

    class solution

    {

    static float CPwithProfit(int sellingPrice, int profit)

    {

        float costPrice;

        costPrice = (sellingPrice * 100) / (100 + profit);

        return costPrice;

    }

    static float CPwithLoss(int sellingPrice, int loss)

    {

        float costPrice;

        costPrice = (sellingPrice * 100) / (100 - loss);

        return costPrice;

    }

    public static void main(String args[])

    {

        int SP, profit, loss;

        SP = 1020;

        profit = 20;

        System.out.println("Cost Price = "+CPwithProfit(SP, profit));

        SP = 900;

        loss = 10;

        System.out.println("Cost Price = "+CPwithLoss(SP, loss));

        SP = 42039;

        profit = 8;

        System.out.println("Cost Price = "+CPwithProfit(SP, profit));

    }

    }

    Python3

    def CPwithProfit(sellingPrice, profit):

        costPrice = ((sellingPrice * 100.0) /

                            (100 + profit))

        return costPrice

    def CPwithLoss(sellingPrice, loss):

        costPrice = ((sellingPrice * 100.0) /

                              (100 - loss))

        return costPrice

    if __name__ == '__main__':

        SP = 1020

        profit = 20

        print("Cost Price =", CPwithProfit(SP, profit))

        SP = 900

        loss = 10

        print("Cost Price =", CPwithLoss(SP, loss))

        SP = 42039

        profit = 8

        print("Cost Price =", int(CPwithProfit(SP,

                                         profit)))

    C#

    using System;

    class solution

    {

    static float CPwithProfit(int sellingPrice, int profit)

    {

        float costPrice;

        costPrice = (sellingPrice * 100) / (100 + profit);

        return costPrice;

    }

    static float CPwithLoss(int sellingPrice, int loss)

    {

        float costPrice;

        costPrice = (sellingPrice * 100) / (100 - loss);

        return costPrice;

    }

    public static void Main()

    {

        int SP, profit, loss;

        SP = 1020;

        profit = 20;

        Console.WriteLine("Cost Price = "+CPwithProfit(SP, profit));

        SP = 900;

        loss = 10;

        Console.WriteLine("Cost Price = "+CPwithLoss(SP, loss));

        SP = 42039;

        profit = 8;

        Console.WriteLine("Cost Price = "+CPwithProfit(SP, profit));

    }

    }

    PHP

    <?php

    function CPwithProfit($sellingPrice, $profit)

    {

        $costPrice = ($sellingPrice * 100.0) / (100 + $profit);

        return $costPrice;

    }

    function CPwithLoss($sellingPrice, $loss)

    {

        $costPrice = ($sellingPrice * 100.0) / (100 - $loss);

        return $costPrice;

    }

        $SP = 1020;

        $profit = 20;

        echo("Cost Price = ");

        echo(CPwithProfit($SP, $profit));

        echo("\n");

        $SP = 900;

        $loss = 10;

        echo("Cost Price = ");

        echo(CPwithLoss($SP, $loss));

        echo("\n");

        $SP = 42039;

        $profit = 8;

        echo("Cost Price = ");

        echo(CPwithProfit($SP, $profit));

        echo("\n");

    ?>

    Javascript

     function CPwithProfit(sellingPrice,  profit)

    {

        var costPrice;

        costPrice = (sellingPrice * 100) / (100 + profit);  

        return costPrice;

    }

    function CPwithLoss( sellingPrice,  loss)

    {

        var costPrice;

        costPrice = (sellingPrice * 100) / (100 - loss);

        return costPrice;

    }

        var SP, profit, loss;

        SP = 1020;

        profit = 20;

        document.write("Cost Price = " + CPwithProfit(SP, profit) + "<br>");

        SP = 900;

        loss = 10;

        document.write("Cost Price = " + CPwithLoss(SP, loss)  + "<br>");

        SP = 42039;

        profit = 8;

        document.write("Cost Price = " + CPwithProfit(SP, profit)  + "<br>");

     </script>

    Output:

    Cost Price = 850
    Cost Price = 1000
    Cost Price = 38925

    Time Complexity: O(1)

    Auxiliary Space: O(1)


    How do you find selling price when profit and profit is given?

    Cost price = Selling price − profit ( when selling price and profit is given ) Cost price = Selling price + loss ( when selling price and loss is given ) Cost price =100×Selling Price100+Profit%( when selling price and profit % is given ) Cost price =100×Selling Price100−loss%( when selling price and loss % is given )

    How do you find the selling price from a profit percentage?

    How to calculate selling price using cost and profit percent? Selling Price = Cost Price [100+ProfitPercentage100]; [Here, cost price and profit% are known.] 1.

    What is the formula for selling price?

    Determine the total cost of all units purchased. Divide the total cost by the number of units purchased to get the cost price. Use the selling price formula to calculate the final price: Selling Price = Cost Price + Profit Margin.

    How do you find SP when CP and profit percentage is given?

    The formulas for profit and loss percentage are given below:.
    Profit percentage(P%) = (Profit /Cost Price) × 100..
    Loss percentage(L%) = (Loss / Cost price) × 100..
    S.P. = {(100 + P%)/100} × CP(if SP > CP).
    S.P. = {(100 – L%)/100} × CP(if SP < CP).
    C.P. = {100/(100 + P%)} × SP(if SP > CP).