✓ Link copied to clipboard
C 📅 June 30, 2026 ⏱ 5 min read

C Program to Calculate Simple and Compound Interest

C Program to Calculate Simple and Compound Interest

Interest calculations are super important in finance, and you can use simple formulas to compute them. This program figures out both simple and compound interest in C. For instance, if you enter a principal of 1000, a rate of 5%, and a time of 2 years, it’ll calculate both types of interest and show you the results.

Let’s see how to do this in C.

Prerequisites for the Interest Calculation Program in C

Make sure you're ready with the following:

  • Understanding of printf and scanf for input and output
  • Basic arithmetic operations like multiplication and division
  • Use of math.h for power calculation in compound interest
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler

Source Code of C Program to Calculate Simple Interest and Compound Interest

Here's the C code that calculates both simple and compound interest:

calculate_interest.cC▶ Run
#include <stdio.h>
#include <math.h>

int main() {
    float principal, rate, time, simple_interest, compound_interest;
    printf("Enter principal amount: ");
    scanf("%f", &principal);
    printf("Enter rate of interest: ");
    scanf("%f", &rate);
    printf("Enter time in years: ");
    scanf("%f", &time);

    simple_interest = (principal * rate * time) / 100;
    compound_interest = principal * pow((1 + rate / 100), time) - principal;

    printf("Simple Interest = %.1f\n", simple_interest);
    printf("Compound Interest = %.1f\n", compound_interest);

    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Interest Calculation Program

When you run the program, this is the kind of output you can expect:

output.txtOutput▶ Run
Enter principal amount: 1000
Enter rate of interest: 5
Enter time in years: 2
Simple Interest = 100.0
Compound Interest = 102.5
Output of C Program to Calculate Simple Interest and Compound Interest
Output of C Program to Calculate Simple Interest and Compound Interest

Algorithm to Calculate Interest in C

Calculating interest requires straightforward arithmetic. For simple interest, multiply the principal, rate, and time, then divide by 100. For compound interest, use the power function to compute the terms.

  1. Read the principal, rate of interest, and time from the user.
  2. Calculate simple interest as (principal * rate * time) / 100.
  3. Calculate compound interest using principal * pow((1 + rate / 100), time) - principal.
  4. Output the calculated simple and compound interest.
flowchart TD
  A([Start]) --> B[/Read principal, rate, time/]
  B --> C[Simple Interest = (principal * rate * time) / 100]
  C --> D[compound\_interest = principal * (1 + rate / 100)^time - principal]
  D --> E[/Print simple interest and compound interest/]
  E --> F([End])
Flowchart: the algorithm step by step

How the C Program to Calculate Interest Works

This program does the math to find both simple and compound interest. Let's walk through each part.

  • The program starts by including the stdio.h and math.h headers for basic input/output and mathematical functions.
  • The variables principal, rate, time, simple_interest, and compound_interest are declared as floats to handle decimal values.
  • Using printf, the program prompts the user to enter the principal amount, rate of interest, and time period, and stores them using scanf.
  • Simple interest is computed as (principal * rate * time) / 100.
  • Compound interest is calculated with principal * pow((1 + rate / 100), time) - principal, where pow calculates the power.
  • Finally, it prints the calculated values of simple and compound interest with printf.
  • The program ends with a return statement.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What does the compound interest formula require?

🎉Correct! Compound interest requires principal, rate, time, and sometimes frequency for more complex calculations.
🤔Not quite. Think about all the factors that influence compound interest.

Time and Space Complexity of the Interest Calculation Program

Analyzing the complexity helps in understanding the program's efficiency.

Time Complexity: O(1). The calculations involve a fixed number of operations: reading inputs, calculating interests, and printing results, which do not depend on the input size.

Space Complexity: O(1). The program uses a constant amount of memory to store the variables principal, rate, time, simple_interest, and compound_interest, which remain constant irrespective of input size.

⚠️

Common mistake:If you forget to include math.h, you'll get errors when using pow for compound interest calculations.

Key takeaway:This program calculates both simple and compound interest efficiently with simple arithmetic in C.

FAQs About Interest Calculation in C

Here are some common questions students have about calculating interest in C.

Simple interest is based on the principal only. But compound interest factors in the principal and any accumulated interest.
The math.h library helps with math functions like pow, which is needed for compound interest calculations.
While float works for reasonably large numbers, go for double for big precision.
Sure, you can tweak the formula to include compounding frequency, like monthly.
A negative interest rate means the principal shrinks over time instead of growing.
scanf grabs formatted input from the console and stores it in the variables you give.

If you found this program helpful, check out these related programs:

Conclusion

This interest calculator’s a handy tool, showing off some basic arithmetic in C. You can expand it to cover different compounding periods or fit it into a bigger finance application. This kind of logic pops up all over in real-world finance. So dive deeper with more complex programs next!

Check out more C concepts in our C quiz or play with other examples in the C compiler.