Area and Perimeter of Rectangle in PL/SQL

Prerequisite
Examples:
Input: l = 2, b = 2
Output: Area = 4, Perimeter = 8

Input: l = 4, b = 8
Output: Area = 32, Perimeter=24
Mathematical Formula:
-- Declaration statement 
DECLARE
  -- Declaration of length and assigning values 
  l NUMBER(4, 2) := 3; 
  --Declaration of breadth and assigning values 
  b NUMBER(4, 2) := 7; 
  --Declaration of a variable for Area of rectangle 
  a NUMBER(4, 2); 
  
  --Declaration of a variable for perimeter 
  p NUMBER(4, 2); 
BEGIN 
    
  -- calculate area and perimeter
  a := l * b; 
  p := 2 * (l + b); 
  
  --Display result 
  dbms_output.Put_line('Area of the rectangle is  ' 
  || a); 
  dbms_output.Put_line('Perimeter of the rectangle is ' 
  || p); 
END
--ENd program

                    
Output:
Area of the rectangle is 21
Perimeter of the rectangle is 20

Contact Us