Find Selling Price from given Profit Percentage and Cost - GeeksforGeeks

15 Apr, 2021
Given the Cost price 
*** QuickLaTeX cannot compile formula:
 

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

and Profit Percentage 
*** QuickLaTeX cannot compile formula:
 

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

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:  
Find the Decimal Equivalent of the profit Percentage, for this divide the percentage by 100.Add 1 to get the decimal Equivalent of unit price increase.Take product of Cost price with the above result to get the selling price.
Find the Decimal Equivalent of the profit Percentage, for this divide the percentage by 100.
Add 1 to get the decimal Equivalent of unit price increase.
Take product of Cost price with the above result to get the selling price.
Below is the implementation of the above approach:Program: 
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation of above approach #include <iostream>using namespace std; // Function to calculate the Selling Pricefloat 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 codeint main(){     // Get the CP and Profit%    float C = 720, P = 13;     // Printing the returned value    cout << SellingPrice(C, P);     return 0;}
// Java implementation of above approach import java.util.*; class solution{ // Function to calculate the Selling Pricestatic 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 codepublic 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)); } }
# Python 3 implementation of# above approach # Function to calculate the# Selling Pricedef SellingPrice (CP, PP):         # Decimal Equivalent of    # Profit Percentage    Pdecimal = 1 + ( PP / 100 )         res = Pdecimal * CP         # return the calculated    # Selling Price    return res # Driver codeif __name__ == "__main__" :     # Get the CP and Profit %    C = 720    P = 13         # Printing the returned value    print(SellingPrice(C, P))
// C# implementation of above approachusing System; class GFG{ // calculate Nth term of seriesstatic 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 Codepublic 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// PHP implementation of above approach // Function to calculate the Selling Pricefunction 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?>
<script> // Javascript implementation of above approach // Function to calculate the Selling Pricefunction SellingPrice(CP, PP){     // Decimal Equivalent of Profit Percentage    var P_decimal = 1 + (PP / 100);     // Find the Selling Price    var res = P_decimal * CP;     // return the calculated Selling Price    return res.toFixed(1);} // Driver code// Get the CP and Profit%var C = 720, P = 13;// Printing the returned valuedocument.write( SellingPrice(C, P));  </script>
813.6
 
Sanjit_Prasad
SURENDRA_GANGWAR
Mithun Kumar
rutvik_56
Aptitude
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Merge two sorted arrays
Modulo Operator (%) in C/C++ with Examples
Prime Numbers
Program to find sum of elements in a given array
Program for Decimal to Binary Conversion
Python Dictionary
Arrays in C/C++
Reverse a string in Java
Inheritance in C++
Interfaces in Java