Simple interest can be defined as the amount of interest we have to pay for a principal amount we have taken from a financial institution at a certain rate of interest. For a better understanding of this simple interest calculation C program, we always recommend you to learn the basic topics of C programming listed below:
This C program calculates the Simple Interest (SI), given the Principal Amount (p), Rate of Interest (r), and Time (n). Simple Interest (SI) is the amount of interest we need to pay for a certain principal amount that we took from a bank or some financial institution for a certain period of time at a rate of interest.
Simple Interest is calculated by using the formula "SI = p*n*r /100". Where
Let us take an example to understand better,
that means, we have to pay 500 for 5 years.
Similarly, to calculate Simple Interest half-yearly and quarterly, we need the principal amount, rate of interest, and time.
Now let's see how we use this logic in the C program. After accepting user input for the principal amount (p), rate of interest (r), and time (t). We define variables as float
datatype. In this C program, we use 5.2 f precision, in which 5 represents the total number of digits and 2 is the number of decimal points. It is for getting a better viewing experience in the simple interest.
The library function scanf
is used to take the three values and stored them in variables. Then according to the Simple Interest Formula, these three values are multiplied together and divide that value by 100, and store result in the variable 'si';
STEP 1: Import the Header Libraries to use the built-in functions in the C program such as stdio.h
STEP 2: Use the main() function to start the execution of the C program.
STEP 3: Initialize some variables for the principal amount (p), simple interest (si), rate of interest (r), and number of years (n),
STEP 4: Accept the values from the user for the principal amount, rate of interest, and number of years using printf
and scanf
built-in functions in stdio.h
library. We use the float
datatype with some precision.
STEP 5: Calculate the simple interest using the formula p*n*r/100.
STEP 6: With help of the printf
function and float
datatype with some precision we print the values of p. n, r, and the Simple Interest (si) using C program syntax.
#include <stdio.h>
void main() {
float p, r, si;
int t;
printf("Enter the values of p, r and t\n");
scanf("%f %f %d", & p, & r, & t);
si = (p * r * t) / 100.0;
printf("Amount = Rs. %5.2f", p);
printf("Rate = Rs. %5.2f\n", r);
printf("Time = %d years\n", t);
printf("Simple interest = %5.2f\n", si);
}
Enter the values of p,r, and t 2000 8 3 Amount = Rs. 2000.00 Rate = Rs. 8.00% Time = 3 years Simple interest = 480.00