Open In App

Program to find Simple Interest and Compound Interest in PL/SQL

Improve
Improve
Like Article
Like
Save
Share
Report
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:   \begin{math}  SI=(P*R*I)/100 \end{math}  Formula for Compound Interest:   \begin{math}  CI = P * Power(1 + (R/100) ^ t) \end{math}  Where: P: Principal (original amount) R: Rate of Interest (in %) T: Time period Below is the required implementation:-
  DECLARE
    --declaration of principal variable
    p  NUMBER(9, 2);
    ----declaration of rate variable
    r  NUMBER(9, 2);
    --declaration of time period variable
    t  NUMBER(9, 2);
    --declaration of simple interest variable
    si NUMBER(9, 2);
    ci NUMBER(9, 2);
BEGIN
    --Code Block Start 
    --assigning principal values
    p := 33000;
  
    --assigning rate  values
    r := 7;
  
    --assigning time period values
    t := 6;
  
    --To calculate SI by simple 
    --mathematical formula
    si := ( p * r * t ) / 100;
  
    ci := p * Power (1 + ( r / 100 ),t);
  
    --Print Result of SI.........
    dbms_output.Put_line('Simple Interest = '
                         ||si);
  
    dbms_output.Put_line('Compound interest = '
                         || ci);
END;
--End program   

                    
Output
Simple Interest = 13860
Compound interest = 49524.1


Last Updated : 02 Jul, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads