Given the Cost price
and Profit Percentage
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.
Below is the implementation of the above approach:
Program:
C++
#include <iostream>
using namespace std;
float SellingPrice( float CP, float PP)
{
float P_decimal = 1 + (PP / 100);
float res = P_decimal * CP;
return res;
}
int main()
{
float C = 720, P = 13;
cout << SellingPrice(C, P);
return 0;
}
|
Java
import java.util.*;
class solution
{
static float SellingPrice( float CP, float PP)
{
float P_decimal = 1 + (PP / 100 );
float res = P_decimal * CP;
return res;
}
public static void main(String args[])
{
float C = 720 , P = 13 ;
System.out.println(SellingPrice(C, P));
}
}
|
Python3
def SellingPrice (CP, PP):
Pdecimal = 1 + ( PP / 100 )
res = Pdecimal * CP
return res
if __name__ = = "__main__" :
C = 720
P = 13
print (SellingPrice(C, P))
|
C#
using System;
class GFG
{
static float SellingPrice( float CP,
float PP)
{
float P_decimal = 1 + (PP / 100);
float res = P_decimal * CP;
return res;
}
public static void Main()
{
float C = 720, P = 13;
Console.Write(SellingPrice(C,P));
}
}
|
PHP
<?php
function SellingPrice( $CP , $PP )
{
$P_decimal = 1 + ( $PP / 100);
$res = $P_decimal * $CP ;
return $res ;
}
$C = 720;
$P = 13;
echo SellingPrice( $C , $P );
?>
|
Javascript
<script>
function SellingPrice(CP, PP)
{
var P_decimal = 1 + (PP / 100);
var res = P_decimal * CP;
return res.toFixed(1);
}
var C = 720, P = 13;
document.write( SellingPrice(C, P));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)