Hello Guys, How do I calculate tenure (N) from the EMI formula if I know EMI, Principal (P), and Interest rate (R)?

```Example:
P=50000;
EMI=4368;
N(month)=12
```

What should be the rate(R)?

Oct 20, 2022 in Others 495 views

## 1 answer to this question.

Try this:

```#include <iostream>
#include <cmath>
#include <boost/date_time/posix_time/posix_time.hpp>

#define TOLERANCE 0.0000001

using namespace std;
using namespace boost::posix_time;

bool active(true);

// just adjust the calc if this isn't the right formula
//
//     EMI = [P x R x (1+R)^N] / [(1+R)^N-1]
//
double calc(double p, double r, double n) {
return  p * r * pow(r + 1.0, n) / (pow(r + 1.0, n) - 1.0);
}

void timeout_loop() {
ptime start = microsec_clock::local_time();
time_duration timeout(seconds(10));

while(active) {

if((microsec_clock::local_time() - start).total_milliseconds() > timeout.total_milliseconds()) {
cout << "timeout" << endl;
active = false;
}
}
}

int main() {
double p(50000.0);
double target(4368.0);
double n(12.0);

double min(0.0);
double max(1.0);
double current = (max + min) / 2.0;

while(active) {
double emi = calc(p, current, n);

if((target - emi) > TOLERANCE) {
min = current;
current = (max + min) / 2.0;
} else if((emi - target) > TOLERANCE) {
max = current;
current = (max + min) / 2.0;
} else {
cout << setprecision(12) << current << endl;
break;
}
}

active = false;

return 0;
}```
• 63,700 points

## How do I push a new local branch to a remote Git repository and track it too?

In Git 1.7.0 and later, you can ...READ MORE

## How do I UPDATE from a SELECT in SQL server?

In SQL Server, it is possible to insert ...READ MORE

## Goal Seek in Excel

The pmt function we are using, which ...READ MORE

## Historical Yahoo Finance API On Fritz Again?

It appears that Yahoo updated its finance ...READ MORE

## Calculating a Rolling IRR in Excel

I'm assuming a little bit here, but ...READ MORE

## Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE