C++ program to find the rate percentage from compound interest of consecutive years


In this tutorial, we will be discussing a program to find the rate percentage from compound interest of the consecutive years.

For this, we will be provided with two integers say A and B that are the interests of two consecutive years. Our task is to find the rate of interest for the given values.

Finding the relation between the given values and eliminating the principal amount, we get the formula as

rate = ((B-A)*100)/A

Example

#include <bits/stdc++.h>
using namespace std;
//calculating the rate of interest
float calc_rate(int N1, int N2) {
   float rate = (N2 - N1) * 100 / float(N1);
   return rate;
}
int main() {
   int N1 = 15, N2 = 18;
   cout << calc_rate(N1, N2) << "%" << endl;
   return 0;
}

Output

20%

Updated on: 09-Jul-2020

102 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements