Find cost price from given selling price and profit or loss percentage | Function to calculate cost price with profit ; required formula to calculate CP with profit ; Function to calculate cost price with loss ; required formula to calculate CP with loss ; Driver code
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 ( " " + CPwithProfit ( SP , profit ) + " " ) ; SP = 900 ; loss = 10 ; document . write ( " " + CPwithLoss ( SP , loss ) + " " ) ; SP = 42039 ; profit = 8 ; document . write ( " " + CPwithProfit ( SP , profit ) + " " ) ;