C++ program to compute simple interest and compound interest.
Q27. Write a program to compute simple interest and compound interest.
Ans.
#include<iostream.h>
#include<math.h> //for pow()
#include<conio.h> //for clrscr()
//Main Function
void main()
{
float principle,rate,time,n,SI,CI,f;
clrscr(); //for clear screen
cout<<“\n Enter Principle Amount: “;
cin>>principle;
cout<<“\n Enter Interest Rate: “;
cin>>rate;
cout<<“\n Enter Time Period in years: “;
cin>>time;
cout<<“\n Enter the number of periods: “;
cin>>n;
//SI=PRT/100
SI=((principle*rate*time)/100);
//CI=P[POW((1+R),N)-1]
rate=rate/100;
CI=(principle * ( (pow((1+rate),n)) -1));
cout<<“\n Simple Interest: Rs.”<<SI;
cout<<“\n Compound Interest: Rs.”<<CI;
getch(); //To hold output screen
}
//End of main()
Output:
Enter Principle Amount: 5000
Enter Interest Rate: 5
Enter Time Period in years: 10
Enter the number of periods: 12
Simple Interest: Rs.2500
Compound Interest: Rs.3979.281738