Header-C
Header-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.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

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

error

Enjoy this blog? Please spread the word :)