C program to calculate Compound Interest

Previous Program Next Exercise

Write a C program to input principle (amount), time and rate (P, T, R) and find Compound Interest. How to calculate compound interest in C programming. Logic to calculate compound interest in C program.



Enter principle (amount): 1200
Enter time: 2
Enter rate: 5.4


Compound Interest = 133.099197

Required knowledge

Fundamentals of C, Data types, Talking user input in C

Compound Interest formula

Formula to calculate compound interest annually is given by -

Compound interest formula
P is principle amount
R is the rate and
T is the time span

Logic to calculate compound interest

The real logic to calculate compound interest lies in applying the formula. We need to convert the above mathematical formula for CI in programming notation. For that we must first know how to find power of any number.

Step by step descriptive logic to find compound interest -

  1. Input principle amount in some variable say principle.
  2. Input time in some variable say time.
  3. Input rate in some variable say rate.
  4. Apply the formula for compound interest. Which is given by - CI = principle * pow((1 + rate / 100), time) - 1.
  5. Finally print the resultant CI.

Program to calculate compound interest

 * C program to calculate Compound Interest

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

int main()
    float principle, rate, time, CI;

    // Read principle, time and rate
    printf("Enter principle (amount): ");
    scanf("%f", &principle);

    printf("Enter time: ");
    scanf("%f", &time);

    printf("Enter rate: ");
    scanf("%f", &rate);

    // Calculate compound interest
    CI = principle* (pow((1 + rate / 100), time) - 1);

    // Print the resultant CI
    printf("Compound Interest = %f", CI);

    return 0;
Enter principle (amount): 1200
Enter time: 2
Enter rate: 5.4
Compound Interest = 133.099197

Happy coding ;)

Recommended posts

Previous Program Next Exercise
Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)

No comments:

Post a Comment