📜  单利要求本金变成自身Y倍所需的时间

📅  最后修改于: 2021-05-04 10:29:40             🧑  作者: Mango

假设在N1年内有一定数量的货币变为自身的T1倍。任务是找到年数,即N2,以使该数量以相同的单利利率成为T2倍。
例子:

方法:

公式:

下面是上述方法的实现:

C++
// C++ implementaion of the approach
#include 
using namespace std;
 
// Function to return the no. of years
float noOfYears(int t1, int n1, int t2)
{
    float years = ((t2 - 1) * n1 / (float)(t1 - 1));
 
    return years;
}
 
// Driver code
int main()
{
    int T1 = 3, N1 = 5, T2 = 6;
 
    cout << noOfYears(T1, N1, T2);
 
    return 0;
}


Java
// Java implementaion of the approach
class GFG
{
     
// Function to return the no. of years
static float noOfYears(int t1, int n1, int t2)
{
    float years = ((t2 - 1) * n1 / (float)(t1 - 1));
 
    return years;
}
 
// Driver code
public static void main(String[] args)
{
    int T1 = 3, N1 = 5, T2 = 6;
 
    System.out.println(noOfYears(T1, N1, T2));
}
}
 
// This code is contributed by Code_Mech


Python3
# Python3 implementation of the approach
 
# Function to return the no. of years
def noOfYears(t1, n1, t2):
 
    years = (t2 - 1) * n1 / (t1 - 1)
    return years
 
# Driver code
if __name__ == "__main__":
 
    T1, N1, T2 = 3, 5, 6
    print(noOfYears(T1, N1, T2))
     
# This code is contributed
# by Rituraj Jain


C#
// C# implementation for above approach
using System;
 
class GFG
{
     
// Function to return the no. of years
static float noOfYears(int t1, int n1, int t2)
{
    float years = ((t2 - 1) * n1 / (float)(t1 - 1));
 
    return years;
}
 
// Driver code
public static void Main(String[] args)
{
    int T1 = 3, N1 = 5, T2 = 6;
 
    Console.WriteLine(noOfYears(T1, N1, T2));
}
}
 
/* This code contributed by PrinciRaj1992 */


PHP


Javascript


输出:
12.5