Program to calculate Profit Or Loss
Given the Cost Price(CP) and Selling Price(SP) of a product. The task is to Calculate the Profit or Loss.
Examples:
Input: CP = 1500, SP = 2000 Output: 500 Profit Input: CP = 3125, SP = 1125 Output: 2000 Loss
Formula:
Profit = (Selling Price - Cost Price) Loss = (Cost Price - Selling Price)
Below is the required implementation:
C++
// C++ code to demonstrate Profit and Loss #include <iostream> using namespace std; // Function to calculate Profit. int Profit(int costPrice, int sellingPrice) { int profit = (sellingPrice - costPrice); return profit; } // Function to calculate Loss. int Loss(int costPrice, int sellingPrice) { int Loss = (costPrice - sellingPrice); return Loss; } // Driver Code. int main() { int costPrice = 1500, sellingPrice = 2000; if (sellingPrice == costPrice) cout << "No profit nor Loss"; else if (sellingPrice > costPrice) cout << Profit(costPrice, sellingPrice) << " Profit "; else cout << Loss(costPrice, sellingPrice) << " Loss "; return 0; } |
chevron_right
filter_none
Java
// Java code to demonstrate // Profit and Loss class GFG { // Function to calculate Profit. static int Profit(int costPrice, int sellingPrice) { int profit = (sellingPrice - costPrice); return profit; } // Function to calculate Loss. static int Loss(int costPrice, int sellingPrice) { int Loss = (costPrice - sellingPrice); return Loss; } // Driver Code. public static void main(String[] args) { int costPrice = 1500, sellingPrice = 2000; if (sellingPrice == costPrice) System.out.println("No profit nor Loss"); else if (sellingPrice > costPrice) System.out.println(Profit(costPrice, sellingPrice) + " Profit "); else System.out.println(Loss(costPrice, sellingPrice) + " Loss "); } } // This code is contributed // by ChitraNayal |
chevron_right
filter_none
Python 3
# Python 3 program to demonstrate # Profit and Loss # Function to calculate Profit. def Profit(costPrice, sellingPrice) : profit = (sellingPrice - costPrice) return profit # Function to calculate Loss. def Loss(costPrice, sellingPrice) : Loss = (costPrice - sellingPrice) return Loss # Driver code if __name__ == "__main__" : costPrice, sellingPrice = 1500, 2000 if sellingPrice == costPrice : print("No profit nor Loss") elif sellingPrice > costPrice : print(Profit(costPrice, sellingPrice), "Profit") else : print(Loss(costPrice, sellingPrice), "Loss") # This code is contributed by ANKITRAI1 |
chevron_right
filter_none
C#
// C# code to demonstrate Profit and Loss using System; class GFG { // Function to calculate Profit static int Profit(int costPrice, int sellingPrice) { int profit = (sellingPrice - costPrice); return profit; } // Function to calculate Loss static int Loss(int costPrice, int sellingPrice) { int Loss = (costPrice - sellingPrice); return Loss; } // Driver Code public static void Main() { int costPrice = 1500, sellingPrice = 2000; if (sellingPrice == costPrice) Console.Write("No profit nor Loss"); else if (sellingPrice > costPrice) Console.Write(Profit(costPrice, sellingPrice) + " Profit "); else Console.Write(Loss(costPrice, sellingPrice) + " Loss "); } } // This code is contributed by ChitraNayal |
chevron_right
filter_none
PHP
<?php // PHP code to demonstrate // Profit and Loss // Function to calculate Profit. function Profit($costPrice, $sellingPrice) { $profit = ($sellingPrice - $costPrice); return $profit; } // Function to calculate Loss. function Loss($costPrice, $sellingPrice) { $Loss = ($costPrice - $sellingPrice); return $Loss; } // Driver Code. $costPrice = 1500; $sellingPrice = 2000; if ($sellingPrice == $costPrice) echo "No profit nor Loss"; else if ($sellingPrice > $costPrice) echo Profit($costPrice, $sellingPrice)." Profit "; else echo Loss($costPrice, $sellingPrice)." Loss "; // This code is contributed // by ChitraNayal ?> |
chevron_right
filter_none
OUTPUT :
500 Profit
Recommended Posts:
- Loss when two items are sold at same price and same percentage profit/loss
- Program to calculate the profit sharing ratio
- Program to find the profit or loss when CP of N items is equal to SP of M items
- Find cost price from given selling price and profit or loss percentage
- Calculate the loss incurred in selling the given items at discounted price
- Program to calculate value of nCr
- Program to calculate age
- C program to calculate the value of nPr
- Efficient program to calculate e^x
- Program to calculate the value of sin(x) and cos(x) using Expansion
- Program to Calculate e^x by Recursion
- Write a program to calculate pow(x,n)
- Program to calculate the value of nCr Efficiently
- Program to Calculate the Perimeter of a Decagon
- Program to calculate Root Mean Square
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.

