Write a C Program to Find Compound Interest.

Prince Patel
By -
0

Write a C Program to Find Compound Interest.


In this article, we will calculate the compound interest. Compound interest can be calculated using the formula.

        Compound Interest = Principal * (1 + (Rate / 100))^Time - Principal

Where:

Principal: The initial amount of money.
Rate: The rate of interest per annum.
Time: The time period in years.

Here's a C program to Find Compound Interest:

#include<stdio.h>
#include<conio.h>

void main()
{
    // Declare and initialize variables
    float principal, rate, time, compoundInterest;

    // Get input from the user
    printf("Enter the principal amount: ");
    scanf("%f", &principal);

    printf("Enter the rate of interest (per annum): ");
    scanf("%f", &rate);

    printf("Enter the time (in years): ");
    scanf("%f", &time);

    // Calculate compound interest
    compoundInterest = principal * (pow(1 + (rate / 100), time)) - principal;

    // Display the result
    printf("Principal Amount: $%.2f\n", principal);
    printf("Rate of Interest: %.2f%%\n", rate);
    printf("Time (in years): %.2f\n", time);
    printf("Compound Interest: ₹%.2f\n", compoundInterest);
}

  • We first declare three variables principal, rate, and time to store the input values. 
  • We then use printf and scanf functions to get these values from the user. 
  • After obtaining the values, we calculate the compound interest using the formula and store it in the variable compoundInterest
  • Finally, we display the result using printf with %.2f to print the result up to two decimal places.
Output:




Tags:

Post a Comment

0Comments

Post a Comment (0)