C program to calculate Compound Interest

C Programming Language / Fundamentals of C Language

2700

Program:

/**
 * 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;
} 

Output:

Enter principle (amount): 1500
Enter time: 2
Enter rate: 6.6
Compound Interest = 204.533997
Press any key to continue . . .

Explanation:

"Exploring the C Program to Calculate Compound Interest"

  1. Importing Required Libraries

    • The program includes the header files 'stdio.h' and 'math.h' to use standard input/output functions and mathematical functions.
  2. Main Function

    • The main function starts with the opening and closing brackets '{}'.
  3. Declaration of Variables

    • The program declares four float variables 'principle', 'rate', 'time', and 'CI' to store the principle amount, interest rate, time and calculated compound interest respectively.
  4. Reading Input

    • The program uses the 'printf()' function to display the prompt "Enter principle (amount):" and the 'scanf()' function to read the principle amount from the user.
    • Similarly, the time and rate are read from the user.
  5. Calculating Compound Interest

    • The formula for compound interest is applied to calculate the compound interest.
    • The formula used is principle * (pow((1 + rate / 100), time) - 1), where 'pow()' is a mathematical function to calculate power.
  6. Displaying Result

    • The program uses the 'printf()' function to display the calculated compound interest with the message "Compound Interest = %f".
  7. Return Statement

    • The main function returns 0, which indicates the successful execution of the program.

"In conclusion, the C program to calculate compound interest is a simple yet useful program for students, financial analysts, and researchers. The program is easy to understand and can be used to calculate compound interest for various scenarios.


This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.