next up previous
Next: Operator Precedence Up: Introduction to Fortran 90 Previous: Declaration Format

 

Area Of a Circle

Write a simple program to read in the radius and calculate the area of the corresponding circle and volume of the sphere. Demonstrate correctness by calculating the area and volume using radii of 2, 5, 10 and -1.

Area of a circle,

equation1244

Volume of a sphere,

equation1247

Hint 1: place the READ, the area calculation and the PRINT statement in a loop as follows. A program template (which is available by clicking here) is given below.

  DO
   PRINT*, "Type in the radius, a negative value will terminate"
   READ*, radius
   IF (radius .LT. 0) EXIT
    ... area calculation
    PRINT*, "Area of circle with radius ",&
            radius, " is ", area
    PRINT*, "Volume of sphere with radius ",&
            radius, " is ", volume
  END DO
  END

In this way when a negative radius is supplied the program will terminate.

Hint 2: tex2html_wrap_inline2855 . tex2html_wrap_inline2857 in Fortran 90 is ATAN.


next up previous
Next: Operator Precedence Up: Introduction to Fortran 90 Previous: Declaration Format

Adam Marshall ©University of Liverpool, 1996
Wed Oct 9 17:39:48 BST 1996