📜  计划从连续年份的复利中找到利率百分比

📅  最后修改于: 2021-04-24 04:09:30             🧑  作者: Mango

给定两个整数N1N2 ,这是连续两年的复利。任务是计算费率百分比。
例子:

方法:利率百分比可以使用公式((N2-N1)* 100)/ N1计算,其中N1是某年的复利, N2是下一年的复利。

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
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


Javascript


输出:
20 %

时间复杂度: O(1)

辅助空间: O(1)