Home / Programs / C program to calculate Compound Interest
🚀 Programming Example

C program to calculate Compound Interest

👁 2,719 Views
💻 Practical Program
📘 Step Learning
C program to calculate Compound Interest

💻 Program Code

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

🖥 Program 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.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.