# Loss when two items are sold at same price and same percentage profit/loss

Given the Selling price i.e **‘SP’** of the two items each. One item is sold at **‘P%’ **Profit and other at **‘P%’ ** Loss. The task is to find out the overall Loss.

**Examples:**

Input:SP = 2400, P = 30%Output:Loss = 474.725Input:SP = 5000, P = 10%Output:Loss = 101.01

**Approach:**

How does the above formula work?

For profit making item :

With selling price (100 + P), we get P profit.

With selling price SP, we get SP * (P/(100 + P)) profit

For loss making item :

With selling price (100 – P), we get P loss.

With selling price SP, we get SP * (P/(100 – P)) loss

Net Loss = Total Loss – Total Profit

= SP * (P/(100 – P)) – SP * (P/(100 + P))

= (SP * P * P * 2) / (100*100 – P*P)

**Note: ** The above formula is applicable only when the Cost price of both the items are different. If CP of both the items are same then, in that case, there is **‘No profit No loss’.**

Below is the implementation of the above approach

## C++

`// C++ implemetation of above approach. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that will ` `// find loss ` `void` `Loss(` `int` `SP, ` `int` `P) ` `{ ` ` ` ` ` `float` `loss = 0; ` ` ` ` ` `loss = (2 * P * P * SP) / ` `float` `(100 * 100 - P * P); ` ` ` ` ` `cout << ` `"Loss = "` `<< loss; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `SP = 2400, P = 30; ` ` ` ` ` `// Calling Function ` ` ` `Loss(SP, P); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implemetation of above approach. ` `class` `GFG ` `{ ` ` ` `// Function that will ` `// find loss ` `static` `void` `Loss(` `int` `SP, ` `int` `P) ` `{ ` ` ` ` ` `float` `loss = ` `0` `; ` ` ` ` ` `loss = (` `float` `)(` `2` `* P * P * SP) / (` `100` `* ` `100` `- P * P); ` ` ` ` ` `System.out.println(` `"Loss = "` `+ loss); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `SP = ` `2400` `, P = ` `30` `; ` ` ` ` ` `// Calling Function ` ` ` `Loss(SP, P); ` `} ` `} ` ` ` `// This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of above approach. ` ` ` `# Function that will find loss ` `def` `Loss(SP, P): ` ` ` ` ` `loss ` `=` `0` ` ` `loss ` `=` `((` `2` `*` `P ` `*` `P ` `*` `SP) ` `/` ` ` `(` `100` `*` `100` `-` `P ` `*` `P)) ` ` ` `print` `(` `"Loss ="` `, ` `round` `(loss, ` `3` `)) ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `SP, P ` `=` `2400` `, ` `30` ` ` ` ` `# Calling Function ` ` ` `Loss(SP, P) ` ` ` `# This code is contributed by Rituraj Jain ` |

*chevron_right*

*filter_none*

## C#

`// C# implemetation of above approach. ` `class` `GFG ` `{ ` ` ` `// Function that will ` `// find loss ` `static` `void` `Loss(` `int` `SP, ` `int` `P) ` `{ ` ` ` ` ` `double` `loss = 0; ` ` ` ` ` `loss = (` `double` `)(2 * P * P * SP) / (100 * 100 - P * P); ` ` ` ` ` `System.Console.WriteLine(` `"Loss = "` `+ ` ` ` `System.Math.Round(loss,3)); ` `} ` ` ` `// Driver Code ` `static` `void` `Main() ` `{ ` ` ` `int` `SP = 2400, P = 30; ` ` ` ` ` `// Calling Function ` ` ` `Loss(SP, P); ` `} ` `} ` ` ` `// This code has been contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach. ` ` ` `// Function that will find loss ` `function` `Loss(` `$SP` `, ` `$P` `) ` `{ ` ` ` ` ` `$loss` `= 0; ` ` ` `$loss` `= ((2 * ` `$P` `* ` `$P` `* ` `$SP` `) / ` ` ` `(100 * 100 - ` `$P` `* ` `$P` `)); ` ` ` `print` `(` `"Loss = "` `. ` `round` `(` `$loss` `, 3)); ` `} ` ` ` `// Driver Code ` `$SP` `= 2400; ` `$P` `= 30; ` ` ` `// Calling Function ` `Loss(` `$SP` `, ` `$P` `); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Loss = 474.725

## Recommended Posts:

- 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 find the profit or loss when CP of N items is equal to SP of M items
- Find Selling Price from given Profit Percentage and Cost
- Overall percentage change from successive changes
- Program to find the Discount Percentage
- Program to find the percentage of difference between two numbers
- Program to calculate Profit Or Loss
- Program to find the rate percentage from compound interest of consecutive years
- QA - Placement Quizzes | Profit and Loss | Question 14
- QA - Placement Quizzes | Profit and Loss | Question 15
- QA - Placement Quizzes | Profit and Loss | Question 4
- QA - Placement Quizzes | Profit and Loss | Question 2
- QA - Placement Quizzes | Profit and Loss | Question 3
- QA - Placement Quizzes | Profit and Loss | Question 5

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.