Open In App

Program to find the rate percentage from compound interest of consecutive years

Last Updated : 31 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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;
}


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


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   


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.


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
?>


Javascript




<script>
 
// javascript implementation of the approach
 
    // Function to return the
    // required rate percentage
    function Rate(N1 , N2) {
        var rate = (N2 - N1) * 100 / N1;
 
        return parseInt( rate);
    }
 
    // Driver code
     
        var N1 = 100, N2 = 120;
 
        document.write(Rate(N1, N2) + " %");
 
// This code contributed by Rajput-Ji
 
</script>


Output: 

20 %

 

Time Complexity: O(1), as there is only basic arithmetic operation.

Auxiliary Space: O(1), as no extra space has been taken.



Similar Reads

Program to find compound interest
What is 'Compound interest' ? Compound interest is the addition of interest to the principal sum of a loan or deposit, or in other words, interest on interest. It is the result of reinvesting interest, rather than paying it out, so that interest in the next period is then earned on the principal sum plus previously-accumulated interest. Compound in
4 min read
JavaScript program to find compound interest
What is 'Compound interest' ? Compound interest is the addition of interest to the principal sum of a loan or deposit, or in other words, interest on interest. It is the result of reinvesting interest, rather than paying it out, so that interest in the next period is then earned on the principal sum plus previously-accumulated interest. Compound in
2 min read
Percentage Change - Formula, Examples, How to Find Percentage Change
Percentage Change is the ratio of change in the value to the original value multiplied by 100. Percentage is defined as a number or ratio expressed as a fraction of 100. The word percentage is derived from the Latin word per centum which means "by the hundred". The percentage is depicted using the symbol "%". Percentage change is found when there i
9 min read
Python Program for Compound Interest
Let us discuss the formula for compound interest. The formula to calculate compound interest annually is given by: A = P(1 + R/100) t Compound Interest = A - P Where, A is amount P is the principal amount R is the rate and T is the time spanFind Compound Interest with Python C/C++ Code # Python3 program to find compound # interest for given values.
3 min read
Percentage increase in the cylinder if the height is increased by given percentage but radius remains constant
Given here is a right circular cylinder, whose height increases by a given percentage, but radius remains constant. The task is to find the percentage increase in the volume of the cylinder.Examples: Input: x = 10 Output: 10% Input: x = 18.5 Output: 18.5% Approach: Let, the radius of the cylinder = rheight of the cylinder = hgiven percentage increa
3 min read
Percentage increase in volume of the cube if a side of cube is increased by a given percentage
Given here is a cube, whose one side is increased by a given percentage. The task is to find percentage increase in the volume of the cube.Examples: Input: x = 10 Output: 33.1% Input: x = 50 Output: 237.5% Approach In a cube, all sides are equal, so, length = breadth = heightlet side of the cube = agiven percentage increase = x%so, volume before in
3 min read
Percentage increase in volume of the sphere if radius is increased by a given percentage
Given here is a sphere, whose radius is increased by a given percentage. The task is to find the percentage increase in the volume of the sphere.Examples: Input: x = 10 Output: 33.1% Input: x = 50 Output: 237.5% Approach: Let, the radius of the sphere = agiven percentage increase = x%volume before increase = 4/3*πa^3new radius after increase = a +
3 min read
Aptitude | Compound Interest | Question 1
An amount of Rs.9000 is invested for 2 years at interest rate of 15% per annual and compounded annually. At the end of 2nd year how much amount will be obtained as interest? (A) Rs. 2902.50 (B) Rs. 2900.50 (C) Rs. 2899.50 (D) Rs. 2899 Answer: (A)Explanation: Amount = P[1+ (R/100)]n where P = principal, R = rate of interest and n = time(years)Amount
1 min read
Aptitude | Compound Interest | Question 2
Ram deposits Rs.2000 each on 1st January and 1st July of a year at the rate of 8% compound interest calculated on half-yearly basis. At the end of the year how much amount he would have? (A) Rs.2150.50 (B) Rs.3182.40 (C) 4243.20 (D) 280.40 Answer: (C) Explanation: We can break this problem into two parts: Rs. 1500 invested for 1 year (Jan to Dec) a
1 min read
Aptitude | Compound Interest | Question 3
Ram invests Rs. 10,000 for 1 year at a rate of 10% per annum compounded yearly and Sita invests the same amount for same time at same rate per annum compounded half yearly. What is the difference between the interests earned by both? (A) Rs. 25.50 (B) Rs. 25 (C) Rs.20.50 (D) Rs.23.75 Answer: (B)Explanation: For Ram:Amount = 10000.[1 + 10/100]1 = Rs
1 min read
Practice Tags :