Find Simple Interest using Inline Calculation
If you only need to perform the conversion once or in a specific context, you can do the calculation inline without defining a separate function.
Example: Illustration of program to find Simple Interest in PHP using inline calculations.
PHP
<?php // Given Values $principal = 1000; $rate = 9; $time = 5; // Calculating the SI $interest = ( $principal * $rate * $time ) / 100; echo "Simple Interest: $interest" ; ?> |
Output
Simple Interest: 450
Time Complexity: O(1)
Auxiliary Space: O(1)
PHP Program to Find Simple Interest
Simple interest is the method to calculate the interest where we only take the principal amount each time without changing it for the interest earned in the previous cycle.
The formula to calculate Simple Interest is –
SI = P * R * T / 100
Where –
- I is the interest.
- P is the principal amount.
- R is the rate of interest per annum.
- T is the time in years.
In this article, we will explore how to calculate simple interest in PHP using different approaches.
Table of Content
- Using Inline Calculation
- Using a Function
- Through User Input using HTML