C program to calculate Compound Interest

Write a C program to input principle (amount), time and rate (P, T, R) from user and find Compound Interest. How to calculate compound interest in C programming if principle, time and rate are given by user. C program for Compound Interest.

Input principle (amount): 1200
Input time: 2
Input rate: 5.4
Output Compound Interest = 133.099197

Required knowledge

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

Compound Interest

Formula for finding compound interest can be given by:
P * ((1 + R / 100) T - 1) (where P = Principle, T = Time, R = Rate)


 * C program to calculate Compound Interest

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

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

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

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

    printf("Compound Interest = %f", CI);

    return 0;

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

Happy coding ;)

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
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment