Simple Interest Calculator in C

 

 

Introduction

Simple interest is a way to calculate interest on a loan or deposit based on the initial principal amount.
The interest is calculated only on the principal amount, not on the accumulated interest. Simple interest is
commonly used in various financial contexts, such as savings accounts, loans, and investments.

Objective

The goal of this program is to demonstrate how to calculate simple interest using the formula:

Simple Interest (SI) = (Principal * Rate * Time) / 100

The program will take the principal, rate of interest, and time period as inputs and output the simple interest.

Code


#include 

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

    // Input principal, rate of interest, and time period
    printf("Enter the principal amount: ");
    scanf("%f", &principal);

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

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

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

    // Output the result
    printf("The simple interest is: %.2f\n", interest);

    return 0;
}
        

Explanation of Program Structure

The program is written in C and follows a basic structure. Here’s a breakdown:

  • Header File: The #include <stdio.h> directive includes the standard input/output library, which is necessary for using functions like printf and scanf.
  • Variables: Four float variables are declared: principal, rate, time, and interest. These are used to store the values for the principal, interest rate, time period, and the calculated interest, respectively.
  • User Input: The program asks the user to input the values for principal, rate, and time using scanf.
  • Simple Interest Calculation: The formula for calculating simple interest is applied: interest = (principal * rate * time) / 100.
  • Output: The program outputs the calculated simple interest to the screen using printf.

How to Run the Program

    1. Step 1: Write or copy the provided C program into a text file and save it with a .c extension (e.g., simple_interest.c).
    2. Step 2: Compile the program using a C compiler, such as gcc. To compile the program, open your terminal or command prompt and run the following command:
gcc simple_interest.c -o simple_interest
    1. Step 3: Once the program is compiled successfully, run the executable to execute the program. In the terminal, type:
./simple_interest
  1. Step 4: The program will prompt you to enter the principal amount, rate of interest, and time period. After inputting these values, it will display the calculated simple interest.

 

Leave a Reply

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