Given that a certain amount of money becomes **T1** times itself in **N1** years. The task is to find the number of years i.e. **N2** so that the amount becomes **T2** times itself at the same rate of simple interest.

**Examples:**

Input:T1 = 5, N1 = 7, T2 = 25

Output:42

Input:T1 = 3, N1 = 5, T2 = 6

Output:12.5

**Approach:**

Let us consider the 1st Example where T1 = 5, N1 = 7, T2 = 25

Now, Let P principal becomes 5P i.e (T1 * P) then Simple interest received is 4P.

(As S.I = Amount – P)Now, in the second case, P has become 25P i.e (T2 * P) then simple interest received is 24P.

Now if we received 4P interest in N1 i.e 7 years then we will get an interest of 24P

in 7 * 6 years i.e in 42 years.

**Formula:**

Below is the implementation of the above approach:

## C++

`// C++ implementaion of the approach ` `#include <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 */` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation for above approach ` ` ` `// Function to return the no. of years ` `function` `noOfYears(` `$t1` `, ` `$n1` `, ` `$t2` `) ` `{ ` ` ` `$years` `= ((` `$t2` `- 1) * ` `$n1` `/ (` `$t1` `- 1)); ` ` ` ` ` `return` `$years` `; ` `} ` ` ` `// Driver code ` `$T1` `= 3; ` `$N1` `= 5; ` `$T2` `= 6; ` ` ` `print` `(noOfYears(` `$T1` `, ` `$N1` `, ` `$T2` `)); ` ` ` `// This code contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

12.5

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.