Friday 29 April 2016

CALCULATE THE AREA OF A CIRCLE FOR A VALUE OF RADIUS VARYING FROM 3 TO 7. STORE THE RADIUS AND THE CORRESPONDING VALUES OF CALCULATED AREA IN A TABLE AREAS.

create table areas ( r number(2), area number (14,2));

declare
r number(5);
area number(14,2);
pi constant number (4,2):=3.14;
begin
r:=3;
while r<=7
loop
area:=pi*power(r,2);
insert into areas values(r,area );
r:=r+1;
end loop;
end;

select * from areas;

14 comments:

  1. Replies
    1. To increment the value of radius.so we can perform the next calculation.

      Delete
  2. To increment the value of radius.so that we can perform next calculation..

    ReplyDelete
  3. DECLARE RADIUS NUMBER; AREA NUMBER(7,2);
    BEGIN
    FOR RADIUS IN 3..7 LOOP AREA :=3.14*RADIUS*RADIUS;
    dbms_output.put_line('Area of circle with radius '|| radius || 'is ' || area); END LOOP;
    end;

    ReplyDelete
    Replies
    1. How to create a table with for loop like
      RADIUS AREA
      ---------- ----------
      3 28.26
      4 50.24
      5 78.5
      6 113.04
      7 153.86

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. declare
    r number(5);
    area number(14,2);
    pi constant number (4,2):=3.14;
    begin
    for r in 3..7
    loop
    area:=pi*power(r,2);
    insert into Circle(RADIUS,AREA) values(r,area );
    end loop;
    end;
    /

    ReplyDelete
  6. Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 3 to 7. Store the radius and the corresponding values of calculated area in an empty table named areas, consisting of two columns radius and area.

    ReplyDelete
  7. --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;

    ReplyDelete
  8. im getting invalid charecter error

    ReplyDelete
  9. What is it's output

    ReplyDelete
  10. not proper output

    ReplyDelete