C program to calculate simple interest has been shown here. Simple interest is the amount of interest that is calculated based on the initial principal, interest rate and time (in years). It is determined by using the following formula:
$SI = {\Large \frac{p * r * t}{100}}$
Here $SI$ represents the simple interest. Pricipal amount, annual interest rate and time have been represented by $p$, $r$ and $t$ respectively. As an example, let's assume $p = 1000$, $r = 5$ and $t = 2$ then by using above formula, we get the value of simple interst $SI = 100$.
The following sections cover C program to calculate the simple interest along with the algorithm, pseudocode and time complexity of the program.
Page content(s):
Additional content(s):
1. Algorithm to calculate simple interest
// Pricipal amount, interest rate and time have been represented by $p$, $r$ and $t$ respectively//
1. Take input of $p$, $r$ and $t$
2. Do computation of $(p*r*t)/100$
3. Return the computed value
2. Pseudocode to calculate simple interest
// Pricipal amount, interest rate, time and simple interest have been represented by $p$, $r$, $t$ and $si$ respectively//
Input: Pricipal $p$, interest rate $r$, time $t$
Output: simple interest $si$
1. Procedure simpleInterest($p$, $r$, $t$):
2.
3.
4. End Procedure
3. Time complexity to calculate simple interest
Time Complexity: O(1)
4. C Program & output to calculate simple interest
/************************************* alphabetacoder.com C program to compute simple interest **************************************/ #include <stdio.h> int main() { // declare variables float p, r, t, si; //take input of principal, interest rate and time printf("Enter principal amount = "); scanf("%f", & p); printf("Enter interest rate = "); scanf("%f", & r); printf("Enter time = "); scanf("%f", & t); //calculate simple interest si = p * r * t / 100; //print result printf("Simple interest = %f\n", si); return 0; }
Output
Enter principal amount = 5000
Enter interest rate = 3.5
Enter time = 5
Simple interest = 875.000000