Question 02 of 02

Compound Interest and Mathematical Calculations using Library Functions (<math.h>)

Write a Turbo C++ program to read Principal (P), Rate of Interest (R), and Time in years (N) from the keyboard. Compute Simple Interest and Compound Interest using mathematical library functions (pow() from <math.h>).

C++
#include <iostream.h>
#include <conio.h>
#include <math.h>

void main() {
    float p, r, t, si, ci, amount;

    clrscr();

    cout << "Enter Principal Amount (P): ";
    cin >> p;
    cout << "Enter Annual Rate of Interest (R%): ";
    cin >> r;
    cout << "Enter Time in Years (T): ";
    cin >> t;

    // Simple Interest: (P * R * T) / 100
    si = (p * r * t) / 100.0;

    // Compound Interest: P * (1 + R/100)^T - P
    amount = p * pow((1 + r / 100.0), t);
    ci = amount - p;

    cout << "\n--- Interest Calculation Results ---" << endl;
    cout << "Simple Interest   = Rs. " << si << endl;
    cout << "Total Amount (CI) = Rs. " << amount << endl;
    cout << "Compound Interest = Rs. " << ci << endl;

    getch();
}
Question 2 of 2