Simple Interest Program in C – Formula, Code, and Examples

Simple interest is the straightforward way to calculate interest on a principal amount over time. The formula is SI = (P × R × T) / 100, where P is the principal, R is the annual interest rate as a percentage, and T is the time in years. This program asks for all three values and prints the interest and the final amount owed (or earned).

The Formula

Symbol Meaning Example
P Principal (starting amount) ₹10,000
R Rate of interest per year (%) 8%
T Time period (years) 3
SI Simple Interest = P×R×T / 100 ₹2,400
A Total Amount = P + SI ₹12,400

Method 1 — Direct Calculation

#include <stdio.h>

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

    printf("Enter principal (P): ");
    scanf("%f", &p);

    printf("Enter rate of interest (R %%): ");
    scanf("%f", &r);

    printf("Enter time period in years (T): ");
    scanf("%f", &t);

    si     = (p * r * t) / 100.0f;
    amount = p + si;

    printf("\nSimple Interest = %.2f\n", si);
    printf("Total Amount    = %.2f\n", amount);

    return 0;
}

Method 2 — Using a Function

Wrapping the formula in a function makes it easy to reuse — for example, when comparing multiple rates or time periods in one run.

#include <stdio.h>

float simple_interest(float p, float r, float t)
{
    return (p * r * t) / 100.0f;
}

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

    printf("Enter principal, rate, and time: ");
    scanf("%f %f %f", &p, &r, &t);

    si = simple_interest(p, r, t);

    printf("\nPrincipal       = %.2f\n", p);
    printf("Rate            = %.2f%%\n", r);
    printf("Time            = %.2f years\n", t);
    printf("Simple Interest = %.2f\n", si);
    printf("Total Amount    = %.2f\n", p + si);

    return 0;
}

How to Compile and Run

gcc -ansi -Wall -Wextra -o simple_interest simple_interest.c
./simple_interest

Sample Input and Output

Enter principal, rate, and time: 10000 8 3

Principal       = 10000.00
Rate            = 8.00%
Time            = 3.00 years
Simple Interest = 2400.00
Total Amount    = 12400.00
Enter principal, rate, and time: 5000 12.5 2

Principal       = 5000.00
Rate            = 12.50%
Time            = 2.00 years
Simple Interest = 1250.00
Total Amount    = 6250.00

Code Explanation

Why float? Principal and rate are often decimal values (₹5000.50, 8.75%), so float is more appropriate than int. For financial applications needing higher precision, use double.

The 100.0f suffix ensures the division is done in floating-point. Without it, if you wrote / 100, the compiler treats 100 as an integer constant — but since p * r * t is already float, this particular division would still be float. The f suffix makes the intent explicit and avoids warnings with -Wextra.

printf("Rate = %.2f%%\n", r) — the %% prints a literal percent sign. A single % would start a format specifier and cause undefined behaviour.

Simple vs compound interest: Simple interest charges interest only on the principal each period. Compound interest charges interest on the principal plus previously earned interest, so the amount grows faster. For a loan of ₹10,000 at 8% for 3 years: SI gives ₹2,400 in interest; compound interest (annually) gives ₹2,597.

What This Program Teaches

  • How to use float for decimal input and calculations
  • How to format output with %.2f for two decimal places
  • How to print a literal % sign using %% in printf
  • How to wrap a formula in a function for reuse

Related C Programs

📖 Learning C from a book? The C Programming Language by K&R (Amazon.in) · Amazon.com

Preparing for a C interview? Practice with the C Programming Quiz — 150+ questions, free on Android.

2 comments on “Simple Interest Program in C – Formula, Code, and Examples

  • Piyush chourasia says:

    display simple interest on principal amount on the basis of rate of interest per annum and the specifiy duration in c language on paper work

    Reply
    • Sandeepa Nadahalli says:

      Hi Piyush,

      Thanks for the comment. But it’s not very clear what you are trying to say here. Can you rephrase it please?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>