C program to calculate Compound Interest

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 = 1333.099243

Required knowledge

Arithmetic operators, Operator precedence and associativity, Data types, Basic input/output

Compound Interest formula

Formula to calculate compound interest annually is given by.

Compound Interest formula (anually)

P is principle amount
R is the rate and
T is the time span

Logic to calculate compound interest

Step by step descriptive logic to find compound interest.

  1. Input principle amount. Store it in some variable say principle.
  2. Input time in some variable say time.
  3. Input rate in some variable say rate.
  4. Calculate compound interest using formula, CI = principle * pow((1 + rate / 100), time).
  5. Finally, print the resultant value of CI.

Read more - Program to find power of a number

Program to calculate compound interest

 * C program to calculate Compound Interest

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

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

    /* Input 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));

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

    return 0;


Enter principle (amount): 1200
Enter time: 2
Enter rate: 5.4
Compound Interest = 1333.099243

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols. as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>