Program to find Simple Interest and Compound Interest in PL/SQL
Last Updated :
02 Jul, 2018
Prerequisite –
PL/SQL introduction
In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations.
Given principal(p), rate(r), time(t), the task is to calculate the simple interest and compound interest.
Examples:
Input: p = 1500
r = 5
t = 3
Output: SI = 225, CI = 1736.44
Input: p = 2700
r = 7
t = 8
Output: SI = 1512, CI = 4639.1
Formula for Simple Interest:
Formula for Compound Interest:
Where:
P: Principal (original amount)
R: Rate of Interest (in %)
T: Time period
Below is the required implementation:-
DECLARE
p NUMBER(9, 2);
r NUMBER(9, 2);
t NUMBER(9, 2);
si NUMBER(9, 2);
ci NUMBER(9, 2);
BEGIN
p := 33000;
r := 7;
t := 6;
si := ( p * r * t ) / 100;
ci := p * Power (1 + ( r / 100 ),t);
dbms_output.Put_line( 'Simple Interest = '
||si);
dbms_output.Put_line( 'Compound interest = '
|| ci);
END ;
|
Output
Simple Interest = 13860
Compound interest = 49524.1
Share your thoughts in the comments
Please Login to comment...