Finding compound interest in C

 #include <stdio.h>

#include <math.h>


int main() {

    double principal, rate, time, amount, compound_interest;


    // Input principal amount

    printf("Enter principal amount: ");

    scanf("%lf", &principal);


    // Input rate of interest (annual)

    printf("Enter rate of interest (in percentage): ");

    scanf("%lf", &rate);


    // Input time period in years

    printf("Enter time in years: ");

    scanf("%lf", &time);


    // Convert rate percentage to decimal

    rate = rate / 100;


    // Calculate total amount using compound interest formula

    amount = principal * pow(1 + rate, time);


    // Calculate compound interest

    compound_interest = amount - principal;


    // Display the results

    printf("Compound Interest = %.2f\n", compound_interest);

    printf("Total amount after %.2f years = %.2f\n", time, amount);


    return 0;

}



Comments