Dado el precio de costo y el porcentaje de ganancia de un artículo, la tarea es calcular el precio de venta.
Ejemplos:
Input: CP = 500, Profit% = 20 Output: SP = 600 Input: CP = 720, Profit% = 13 Output: SP = 813.6
Acercarse:
- Encuentra el Equivalente Decimal del Porcentaje de Ganancia, para ello divide el porcentaje entre 100.
- Sume 1 para obtener el equivalente decimal del aumento del precio unitario.
- Tome el producto del precio de costo con el resultado anterior para obtener el precio de venta.
A continuación se muestra la implementación del enfoque anterior:
Programa:
C++
// 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; }
Java
// 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)); } }
Python3
# 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))
C#
// 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
PHP
<?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 ?>
Javascript
<script> // Javascript implementation of above approach // Function to calculate the Selling Price function 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 value document.write( SellingPrice(C, P)); </script>
Producción:
813.6
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por Krishna_Yadav y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA