next up previous contents
Next: Operator Precedence Up: Area Of a Circle Previous: Area Of a Circle

Solution

 PROGRAM Area_Volume
  REAL :: radius, area, pi
  pi = ATAN(1.0)*4.0
  DO
   PRINT*, "Type in the radius, a negative value will terminate"
   READ*, radius
   IF (radius .LT. 0) EXIT
    area = pi*radius*radius
    Print*, "Area of circle with radius ",&
            radius, " is ", area
    Print*, "Volume of sphere with radius ",&
            radius, " is ", ((4.0/3.0)*radius)*area
  END DO
 END PROGRAM Area_Volume

and results will be (something like):

 Type in the radius, a negative value will terminate
2
 Area of circle with radius    2.000000      is    12.56637    
 Volume of sphere with radius    2.000000      is    33.51032    
 Type in the radius, a negative value will terminate
5
 Area of circle with radius    5.000000      is    78.53982    
 Volume of sphere with radius    5.000000      is    523.5988    
 Type in the radius, a negative value will terminate
10
 Area of circle with radius    10.00000      is    314.1593    
 Volume of sphere with radius    10.00000      is    4188.791    
 Type in the radius, a negative value will terminate
-1


next up previous contents
Next: Operator Precedence Up: Area Of a Circle Previous: Area Of a Circle

©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997
Not for commercial use.