Given two integers **N1** and **N2** which is the **Compound Interest** of two consecutive years. The task is to calculate the rate percentage.

**Examples:**

Input:N1 = 660, N2 = 720

Output:9.09091 %

Input:N1 = 100, N2 = 120

Output:20 %

**Approach:** The rate percentage can be calculated with the formula **((N2 – N1) * 100) / N1** where **N1** is the compound interest of some year and **N2** is the compound interest for the next year.

Let us consider the 1st Example:

The difference between the Compound interest in the two consecutive years is because of the interest received on the previous year interest. Therefore,

–> N2 – N1 = N1 * (Rate / 100)

–> 720 – 660 = 660 * (Rate / 100)

–> (60 / 660) * 100 = Rate

–> Rate = (100 / 11) = 9.09% (Approx)

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the ` `// required rate percentage ` `float` `Rate(` `int` `N1, ` `int` `N2) ` `{ ` ` ` `float` `rate = (N2 - N1) * 100 / ` `float` `(N1); ` ` ` ` ` `return` `rate; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `N1 = 100, N2 = 120; ` ` ` ` ` `cout << Rate(N1, N2) << ` `" %"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the ` ` ` `// required rate percentage ` ` ` `static` `int` `Rate(` `int` `N1, ` `int` `N2) ` ` ` `{ ` ` ` `float` `rate = (N2 - N1) * ` `100` `/ N1; ` ` ` ` ` `return` `(` `int` `)rate; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `N1 = ` `100` `, N2 = ` `120` `; ` ` ` ` ` `System.out.println(Rate(N1, N2) + ` `" %"` `); ` ` ` `} ` `} ` ` ` `// This code has been contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation of the approach ` ` ` `# Function to return the ` `# required rate percentage ` `def` `Rate( N1, N2): ` ` ` `rate ` `=` `(N2 ` `-` `N1) ` `*` `100` `/` `/` `(N1); ` ` ` ` ` `return` `rate ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `N1 ` `=` `100` ` ` `N2 ` `=` `120` ` ` ` ` `print` `(Rate(N1, N2) ,` `" %"` `) ` ` ` `# This code is contributed by ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to return the ` ` ` `// required rate percentage ` ` ` `static` `int` `Rate(` `int` `N1, ` `int` `N2) ` ` ` `{ ` ` ` `float` `rate = (N2 - N1) * 100 / N1; ` ` ` ` ` `return` `(` `int` `)rate; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main () ` ` ` `{ ` ` ` `int` `N1 = 100, N2 = 120; ` ` ` ` ` `Console.WriteLine(Rate(N1, N2) + ` `" %"` `); ` ` ` `} ` `} ` ` ` `// This code has been contributed by ajit. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the ` `// required rate percentage ` `function` `Rate(` `$N1` `, ` `$N2` `) ` `{ ` ` ` `$rate` `= (` `$N2` `- ` `$N1` `) * 100 / ` `$N1` `; ` ` ` ` ` `return` `$rate` `; ` `} ` ` ` `// Driver code ` `$N1` `= 100; ` `$N2` `= 120; ` ` ` `echo` `Rate(` `$N1` `, ` `$N2` `), ` `"%"` `; ` ` ` `// This code is contributed by AnkitRai01 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

20 %

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:

- Program to find compound interest
- Compound Interest
- Aptitude | Compound Interest | Question 4
- Aptitude | Compound Interest | Question 3
- Aptitude | Compound Interest | Question 1
- Aptitude | Compound Interest | Question 2
- Aptitude | Compound Interest | Question 6
- Aptitude | Compound Interest | Question 11
- Aptitude | Compound Interest | Question 5
- Aptitude | Compound Interest | Question 10
- Aptitude | Compound Interest | Question 12
- Aptitude | Compound Interest | Question 8
- Aptitude | Compound Interest | Question 9
- Aptitude | Compound Interest | Question 7
- QA - Placement Quizzes | Compound Interest | Question 14
- QA - Placement Quizzes | Compound Interest | Question 15
- QA - Placement Quizzes | Compound Interest | Question 13
- Program to find simple interest
- Program to find the Discount Percentage
- Program to find the percentage of difference between two numbers

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.