Find Selling Price from given Profit Percentage and Cost

Given the Cost price C and Profit Percentage P of an item, the task is to calculate the Selling Price.

Examples:

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

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

Approach:

  1. Find the Decimal Equivalent of the profit Percentage, for this divide the percentage by 100.
  2. Add 1 to get the decimal Equivalent of unit price increase.
  3. Take product of Cost price with the above result to get the selling price.

Below is the implementation of the above approach:

Program:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation of above approach
  
#include <iostream>
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;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
  
}
  
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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 

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP implementation of above approach
  
// Function to calculate the Selling Price
function SellingPrice($CP, $PP)
{
  
    // Decimal Equivalent of Profit Percentage
    $P_decimal = 1 + ($PP / 100);
  
    // Find the Selling Price
    $res = $P_decimal * $CP;
  
    // return the calculated Selling Price
    return $res;
}
  
// Driver code
  
    // Get the CP and Profit%
    $C = 720;
    $P = 13;
  
    // Printing the returned value
    echo SellingPrice($C, $P);
  
// this code is contributed by mits
?>

chevron_right


Output:

813.6


My Personal Notes arrow_drop_up

Techie Geek

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.