C Program to Calculate Simple Interest and Compound Interest

This program calculates both Simple Interest (SI) and Compound Interest (CI) based on user-provided values for principal, rate of interest, and time period.

Concept Overview

Simple Interest is calculated using the formula SI = (P × R × T) / 100. Compound Interest is calculated using CI = P × (1 + R / 100)^T – P. This program takes user input and applies these formulas to display the results.

Program

C
#include <stdio.h>
#include <math.h>

int main() {
    double principal, rate, time;
    double simpleInterest, compoundInterest;

    printf("Enter Principal: ");
    scanf("%lf", &principal);

    printf("Enter Rate of Interest: ");
    scanf("%lf", &rate);

    printf("Enter Time (in years): ");
    scanf("%lf", &time);

    // Simple Interest Formula
    simpleInterest = (principal * rate * time) / 100;

    // Compound Interest Formula
    compoundInterest = principal * pow((1 + rate / 100), time) - principal;

    printf("Simple Interest = %.2lf\n", simpleInterest);
    printf("Compound Interest = %.2lf\n", compoundInterest);

    return 0;
}

Sample Output

Enter Principal: 1000
Enter Rate of Interest: 5
Enter Time (in years): 2
Simple Interest = 100.00
Compound Interest = 102.50

Explanation

  • `P`, `R`, and `T` represent Principal, Rate of Interest, and Time respectively.
  • The Simple Interest formula `(P × R × T) / 100` gives linear growth over time.
  • The Compound Interest formula `P × (1 + R / 100)^T – P` accounts for interest on accumulated interest.
  • Results are displayed with two decimal places using `%.2f` formatting.
Note: Note: This program assumes that the interest is compounded annually. You can modify the formula for different compounding frequencies (e.g., monthly, quarterly).