calculate-loan

01 Loan payments

Simple Interest Calculator in C: Code & Formula

Calculator No. 01-28875 · Updated · Formula and assumptions shown below

Simple interest $1,500.00
Total amount
$11,500.00
= Principal amount + simple interest
Principal amount
$10,000
Input
Annual interest rate
5 %
Input
You enter
Principal amount ($), Annual interest rate (%), Time period (years)
You get
Simple interest ($), Total amount ($)
Rounding
2 dp

Estimate for education, not financial advice. The result follows from the numbers you enter and the formula shown. It is not a quote or an offer, and it does not include fees, taxes or insurance unless the calculator asks for them. Ask your lender for the exact figures.

This page provides a working simple interest calculator in C, showing the exact code, the formula it uses, and how to adapt it for your own programs. You enter the principal amount, the annual interest rate, and the time period in years, and the calculator returns the simple interest and the total amount (principal plus interest). The C code below is a complete, ready-to-run program that you can compile and use immediately.

Formula

The simple interest formula is:

Simple Interest (SI) = (Principal × Rate × Time) / 100

Where:

  • Principal (P) – the initial amount of money, in dollars ($).
  • Rate (R) – the annual interest rate, in percent (%).
  • Time (T) – the time the money is invested or borrowed, in years.

The total amount (A) is simply A = P + SI.

In C, this translates to: si = (p * r * t) / 100; and total = p + si;.

Worked Example

Using the default values from the calculator: Principal = $10,000, Rate = 5% per year, Time = 3 years.

  1. Multiply principal by rate: 10,000 × 5 = 50,000
  2. Multiply by time: 50,000 × 3 = 150,000
  3. Divide by 100: 150,000 / 100 = 1,500

So the simple interest is $1,500.00. Adding the principal gives a total amount of $11,500.00. The calculator confirms these numbers.

Assumptions

  • The interest rate is an annual rate, and time is measured in years.
  • Interest is calculated only on the original principal, not on previously earned interest (that would be compound interest).
  • No fees, taxes, or other charges are included.
  • The rate is assumed to be constant over the entire period.

How to Write a Simple Interest Calculator in C

Writing a simple interest calculator in C is a common exercise for learning basic input, arithmetic, and output. Here is a complete C program:

#include <stdio.h>

int main() {
    float principal, rate, time, interest, total;

    printf("Enter principal amount: ");
    scanf("%f", &principal);
    printf("Enter annual interest rate (in %%): ");
    scanf("%f", &rate);
    printf("Enter time period (in years): ");
    scanf("%f", &time);

    interest = (principal * rate * time) / 100;
    total = principal + interest;

    printf("Simple Interest = $%.2f\n", interest);
    printf("Total Amount = $%.2f\n", total);

    return 0;
}

This program reads three floating-point numbers, applies the formula, and prints the results with two decimal places. You can compile it with any C compiler (e.g., GCC) and run it.

Common Mistakes and How to Avoid Them

  • Using integer division: In C, if all variables are integers, (p * r * t) / 100 performs integer division, truncating any fractional part. Always use float or double for money and rates.
  • Mixing up rate and time units: The formula assumes the rate is annual and time is in years. If you have a monthly rate or time in months, convert first: time in years = months / 12, or rate per month = annual rate / 12.
  • Forgetting to divide by 100: The rate is a percentage, so you must divide by 100. A common error is using p * r * t without the division.
  • Not rounding to cents: Floating-point arithmetic can produce long decimals. Use printf("%.2f", ...) to display two decimal places.

When to Use Simple Interest vs. Compound Interest

Simple interest is used for short-term loans, certain bonds, and some types of savings accounts where interest is not reinvested. It is straightforward: interest is always calculated on the original principal. Compound interest, on the other hand, adds earned interest back to the principal, so interest grows over time. The formula for compound interest is A = P * (1 + r/n)^(n*t), where n is the number of compounding periods per year. For most long-term investments and mortgages, compound interest applies. This calculator is for simple interest only.

Limitations of the Simple Interest Formula

The simple interest formula assumes a constant rate and no compounding. It does not account for:

  • Variable interest rates that change over time.
  • Fees, penalties, or taxes.
  • Partial payments or prepayments.
  • Inflation or the time value of money beyond the basic interest.

For real-world loans, lenders typically use amortization schedules or compound interest, so the simple interest result is an approximation for educational purposes.

Frequently Asked Questions

How do I calculate simple interest in C using user input?

Use scanf to read the principal, rate, and time as floating-point numbers, then apply the formula interest = (principal * rate * time) / 100; and print the result with printf. The example program above shows the full code.

What is the difference between simple interest and compound interest in C?

Simple interest uses the formula SI = P * R * T / 100. Compound interest uses A = P * pow((1 + r/n), n*t), where r is the decimal rate (rate/100), n is the number of compounding periods per year, and pow is from math.h. Compound interest adds interest to the principal, so it grows faster.

Why does my C program give 0 for simple interest?

This usually happens when you use integer variables. For example, if principal, rate, and time are int, the division by 100 truncates. Declare them as float or double, and make sure to include %f in scanf.

Can I use this calculator for monthly interest?

Yes, but you must convert the time to years. For example, 6 months is 0.5 years. Alternatively, you can adjust the formula to use monthly rate: interest = principal * (annual_rate/12) * months / 100, but the standard formula expects years.

What is the total amount in simple interest?

The total amount is the sum of the principal and the simple interest: Total = P + SI. In the example, $10,000 + $1,500 = $11,500.

This calculator provides an estimate for educational purposes; the exact figures from a lender or financial institution will be in their loan disclosure.

Related

Formula used
in p | Principal amount | $ | 10000 | 0 | 100000000
in r | Annual interest rate | % | 5 | 0 | 100
in t | Time period | years | 3 | 0 | 100
out si | Simple interest | $ | p * r * t / 100 | 2
out total | Total amount | $ | p + si | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard loan formula for this calculation, fixed rate and monthly compounding unless stated, rounded as each result states. Not financial advice; no lender, rate or product is recommended. See formulas and assumptions, the disclaimer or report an error.

More in this section

The whole Loan payments section →