# 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++ implementation 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 implementation 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# implementation 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
- Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant
- Percentage increase in volume of the sphere if radius is increased by a given percentage
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Probability of distributing M items among X bags such that first bag contains N items
- Overall percentage change from successive changes
- Program to calculate Profit Or Loss
- Program to find the Discount Percentage
- QA - Placement Quizzes | Profit and Loss | Question 9
- QA - Placement Quizzes | Profit and Loss | Question 8
- QA - Placement Quizzes | Profit and Loss | Question 11
- QA - Placement Quizzes | Profit and Loss | Question 13

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.