Area and Perimeter of a circle in PL/SQL

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 the radius of a circle and the task is to find the area and perimeter of the circle.
Examples:

Input: 3
Output: Area = 28.26
        Perimeter = 18.84

Input: 7
Output: Area = 153.86
        Perimeter = 43.96

Formula for area and perimeter of circle:
Area:



pi * radius * radius 

Perimeter:

2 * pi * radius

where pi = 3.14

Below is the required implementation:

filter_none

edit
close

play_arrow

link
brightness_4
code

--Find the area and perimeter of circle
DECLARE 
  
    -- Variables to store area and perimeter
    area   NUMBER(6, 2)  ;  
    perimeter   NUMBER(6, 2)  ; 
      
    --Assigning the value of radius 
    radius NUMBER(1) := 3; 
      
    --Constant value of  PI 
    pi CONSTANT NUMBER(3, 2) := 3.14; 
      
BEGIN 
  
        --Formula for area and perimeter of a circle 
        area := pi * radius * radius; 
        perimeter := 2 * pi * radius;
        dbms_output.Put_line('Area = ' || area); 
        dbms_output.Put_line(' Perimeter = ' || perimeter); 
  
END

chevron_right


Output:

Area = 28.26
Perimeter = 18.84


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.