# Program to find the Discount Percentage

Given Marked Price and Selling price as of a product. The task is to calculate the Discount Percentage applied to that product.

Examples:

```Input: M = 120, S = 100
Output: 16.66%

Input: M = 1000, S = 500
Output: 50%
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

The mathematical formula to calculate the Discount Percentage for the product is:

```Discount = Marked Price - Selling price

Therefore,
Discount Percentage = (Discount / Marked Price) * 100
```

Below is the program to find the discount percentage for a product:

## C++

 `// CPP Program to find the Discount Percentage ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to find the Discount Percentage ` `float` `discountPercentage(``float` `S, ``float` `M) ` `{ ` `    ``// Calculating discount ` `    ``float` `discount = M - S; ` ` `  `    ``// Calculating discount percentage ` `    ``float` `disPercent = (discount / M) * 100; ` ` `  `    ``return` `disPercent; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `M, S; ` `    ``M = 120; ` `    ``S = 100; ` `     `  `    ``// Setting the precision to 2 decimals ` `    ``cout << std::fixed << std::setprecision(2) ` `        ``<< discountPercentage(S, M) << ``"%"` `<< endl; ` ` `  `    ``M = 1000; ` `    ``S = 500; ` `     `  `    ``// Setting the precision to 2 decimals ` `    ``cout << std::fixed << std::setprecision(2) ` `        ``<< discountPercentage(S, M) << ``"%"` `<< endl; ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java Program to find the Discount Percentage ` ` `  `import` `java.util.*; ` `import` `java.lang.*; ` `import` `java.io.*; ` ` `  `class` `GFG{ ` `  `  `// Function to find the Discount Percentage ` `static` `float` `discountPercentage(``float` `S, ``float` `M) ` `{ ` `    ``// Calculating discount ` `    ``float` `discount = M - S; ` `  `  `    ``// Calculating discount percentage ` `    ``float` `disPercent = (discount / M) * ``100``; ` `  `  `    ``return` `disPercent; ` `} ` `  `  `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` `    ``int` `M, S; ` `    ``M = ``120``; ` `    ``S = ``100``; ` ` `  `    ``System.out.printf(``"%.2f"``,discountPercentage(S,M)); ` `    ``System.out.println(``"%"``); ` `     `  `  `  `    ``M = ``1000``; ` `    ``S = ``500``; ` ` `  `   ``System.out.printf(``"%.2f"``,discountPercentage(S,M)); ` `    ``System.out.println(``"%"``); ` `} ` `} `

## Python3

 `# Python3 Program to find the  ` `# Discount Percentage ` ` `  `# Function to find the  ` `# Discount Percentage ` `def` `discountPercentage(S, M): ` ` `  `    ``# Calculating discount ` `    ``discount ``=` `M ``-` `S ` ` `  `    ``# Calculating discount percentage ` `    ``disPercent ``=` `(discount ``/``M) ``*` `100` ` `  `    ``return` `disPercent ` ` `  ` `  `# Driver code ` `if` `__name__``=``=``'__main__'``: ` `    ``M ``=` `120` `    ``S ``=` `100` ` `  `    ``print``(discountPercentage(S, M), ``"%"``) ` ` `  `    ``M ``=` `1000` `    ``S ``=` `500` ` `  `    ``print``(discountPercentage(S, M), ``"%"``) ` ` `  `# This code is contribute  ` `# by ihritik `

## C#

 `// C# Program to find the  ` `// Discount Percentage ` `using` `System; ` ` `  `class` `GFG ` `{ ` ` `  `// Function to find the ` `// Discount Percentage ` `static` `float` `discountPercentage(``float` `S,  ` `                                ``float` `M) ` `{ ` `    ``// Calculating discount ` `    ``float` `discount = M - S; ` ` `  `    ``// Calculating discount percentage ` `    ``float` `disPercent = (discount / M) * 100; ` ` `  `    ``return` `disPercent; ` `} ` ` `  `// Driver code ` `static` `public` `void` `Main () ` `{ ` `    ``int` `M, S; ` `    ``M = 120; ` `    ``S = 100; ` ` `  `    ``Console.Write(discountPercentage(S, M)); ` `    ``Console.WriteLine(``"%"``); ` `     `  `    ``M = 1000; ` `    ``S = 500; ` ` `  `    ``Console.Write(discountPercentage(S, M)); ` `    ``Console.Write(``"%"``); ` `} ` `} ` ` `  `// This code is contributed by Raj `

## PHP

 ` `

Output:

```16.67%
50.00%
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up 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.