C Program – Find Simple Interest - Formula & Function

Simple Interest Using Formula

#include <stdio.h>
int main() {
    float principal, rate, time, interest;
    printf("Enter principal amount: ");
    scanf("%f", &principal);
    printf("Enter annual interest rate (in %%): ");
    scanf("%f", &rate);
    printf("Enter time (in years): ");
    scanf("%f", &time);
    interest = (principal * rate * time) / 100;
    printf("Simple Interest = %.2f\n", interest);
    return 0;
}
Enter principal amount: 1000
Enter annual interest rate (in %): 5
Enter time (in years): 3
Simple Interest = 150.00
        

The formula for simple interest multiplies principal, rate and time, and divides by 100 to account for percentage. This method calculates the value directly in the main function.

Simple Interest Using a Function

#include <stdio.h>
float calculateSI(float p, float r, float t) {
    return (p * r * t) / 100;
}
int main() {
    float principal, rate, time, interest;
    printf("Enter principal amount: ");
    scanf("%f", &principal);
    printf("Enter annual interest rate (in %%): ");
    scanf("%f", &rate);
    printf("Enter time (in years): ");
    scanf("%f", &time);
    interest = calculateSI(principal, rate, time);
    printf("Simple Interest = %.2f\n", interest);
    return 0;
}
Enter principal amount: 5000
Enter annual interest rate (in %): 4.5
Enter time (in years): 2
Simple Interest = 450.00
        

Defining a function for the interest calculation helps keep main concise and allows the logic to be reused elsewhere in a larger program.

Sai Kishore Randhi, author
About the author

Sai Kishore Randhi

Embedded systems, VLSI, and chip design

Sai Kishore writes about embedded systems, VLSI, chip design, and the programming concepts behind modern hardware.

View LinkedIn profile ↗