C program to calculate Simple Interest

Topics

  • The program first declares four variables: principal, rate, time, and interest.
  • It then prompts the user to enter the principal amount, rate of interest, and time in years using the printf() and scanf() functions.
  • The formula for calculating simple interest is (principal * rate * time) / 100. The program calculates the simple interest using this formula and stores it in the interest variable.
  • Finally, the program prints the simple interest using the printf() function with a precision of two decimal places.
  • Note that the %.2f in the printf() statement is used to specify the precision of the floating-point number to two decimal places.

#include <stdio.h>

int main() {
    float principal, rate, time, interest;

    printf("Enter principal amount: ");
    scanf("%f", &principal);

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

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

    interest = (principal * rate * time) / 100;

    printf("Simple interest = %.2f", interest);

    return 0;
}

OUTPUT

Enter principal amount: 1000
Enter rate of interest: 5
Enter time in years: 2
Simple interest = 100.00

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *