Given two numbers a and b, where ‘b’ is incremented or decremented by some percentage of ‘a’. The task is to find out that percentage.

**Examples:**

Input: a = 20, b = 25 Output: 25% Difference between 20 and 25 is 5, which is 25 % of 20. (+ve sign indicate increment) Input: a = 25, b = 20 Output: -20% ( -ve sign indicate decrement)

**Formula to calculate percentage:**

(Percentage2 – Percentage1) * 100 / (Percentage1)

## C++

`// C++ program to calculate the percentage ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to calculate the percentage ` `int` `percent(` `int` `a, ` `int` `b) ` `{ ` ` ` `float` `result = 0; ` ` ` `result = ((b - a) * 100) / a; ` ` ` ` ` `return` `result; ` `} ` ` ` `// Driver Code. ` `int` `main() ` `{ ` ` ` `int` `a = 20, b = 25; ` ` ` ` ` `cout << percent(a, b) << ` `"%"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to calculate ` `// the percentage ` `class` `GFG ` `{ ` ` ` `// Function to calculate the percentage ` `static` `int` `percent(` `int` `a, ` `int` `b) ` `{ ` ` ` `float` `result = ` `0` `; ` ` ` `result = ((b - a) * ` `100` `) / a; ` ` ` ` ` `return` `(` `int` `)result; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `a = ` `20` `, b = ` `25` `; ` ` ` ` ` `System.out.println(percent(a, b) + ` `"%"` `); ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 program to calculate ` `# the percentage ` ` ` `# Function to calculate the percentage ` `def` `percent(a, b) : ` ` ` ` ` `result ` `=` `int` `(((b ` `-` `a) ` `*` `100` `) ` `/` `a) ` ` ` ` ` `return` `result ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `a, b ` `=` `20` `, ` `25` ` ` ` ` `# Function calling ` ` ` `print` `(percent(a, b), ` `"%"` `) ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to calculate ` `// the percentage ` `class` `GFG ` `{ ` ` ` `// Function to calculate the percentage ` `static` `int` `percent(` `int` `a, ` `int` `b) ` `{ ` ` ` `float` `result = 0; ` ` ` `result = ((b - a) * 100) / a; ` ` ` ` ` `return` `(` `int` `)result; ` `} ` ` ` `// Driver Code ` `static` `void` `Main() ` `{ ` ` ` `int` `a = 20, b = 25; ` ` ` ` ` `System.Console.WriteLine(percent(a, b) + ` `"%"` `); ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to calculate ` `// the percentage ` ` ` `// Function to calculate ` `// the percentage ` `function` `percent(` `$a` `, ` `$b` `) ` `{ ` ` ` `$result` `= 0; ` ` ` `$result` `= ((` `$b` `- ` `$a` `) * 100) / ` `$a` `; ` ` ` ` ` `return` `$result` `; ` `} ` ` ` `// Driver Code ` `$a` `= 20; ` `$b` `= 25; ` ` ` `echo` `percent(` `$a` `, ` `$b` `) . ` `"%"` `; ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

25%

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.

## Recommended Posts:

- Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Percentage increase in volume of the sphere if radius is increased by a given percentage
- Program to find the Discount Percentage
- Program to find the rate percentage from compound interest of consecutive years
- Loss when two items are sold at same price and same percentage profit/loss
- Find Selling Price from given Profit Percentage and Cost
- Find cost price from given selling price and profit or loss percentage
- Find the percentage change in the area of a Rectangle
- Overall percentage change from successive changes
- Percentage increase in the volume of cuboid if length, breadth and height are increased by fixed percentages
- Python | Percentage increase in the total surface area of the cuboid
- Python | Percentage increase in hemisphere volume if radius is increased
- Percentage change in Hemisphere volume if radius is changed
- Program to find the maximum difference between the index of any two different numbers
- Find the minimum difference between Shifted tables of two numbers
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Count of numbers upto N having absolute difference of at most K between any two adjacent digits
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array

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.