C++ program to calculate simple interest and compound interest
In this tutorial, we will learn how we can calculate simple interest and compound interest using the C++ program. So let’s know what simple interest and compound interest are along with formulas.
SIMPLE INTEREST
It can be calculated on the given principal, rate, and time or we can say the original amount of the loan.
Formula:
S.I = P*R*T/100
where P= principal , R = Rate , T=Time
COMPOUND INTEREST
It is used to when we want to calculate on the principal amount and the accumulated amount there previously. So it is also called interest on interest.
Formula:
p*pow(1+r/100),t )-p
C++ code to calculate simple interest and compound interest
Below is the example of code to calculate simple and compound interest:
#include <iostream> #include <conio> #include <math.h> using namespace std; int main() { clrscr(); float p,r , t , si , ci; p = 1000; r = 5; t = 3; si = (p*r*t)/100; ci = p*pow(1+r/100),t )-p; cout<<"simple interest is "<<si; cout<<"compound interest is "<<ci return 0; }
Output:
simple interest is 1150 compound interest is 1158
Explanation to the code
First, we will put header file math.h so as to import all necessary header files required. Then we will put float p,r,t,si,ci so that these values can take decimal values as well. After that, we will put values p,r,t in the code and write the formulas of simple interest and compound interest. Then the output will be printed on the screen using cout.
Leave a Reply