我已经用Fortran90编写了一个简单的程序来计算三角形的面积。用户输入三角形的三条边,然后程序输出面积。非常简单。
MODULE Triangle_Operations
IMPLICIT NONE
CONTAINS
FUNCTION Area(x,y,z)
REAL :: Area ! function type
REAL, INTENT( IN ) :: x, y, z
REAL :: theta, height
theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))
height = x*SIN(theta); Area = 0.5*y*height
END FUNCTION Area
END MODULE Triangle_Operations
PROGRAM Triangle
USE Triangle_Operations
IMPLICIT NONE
REAL :: a, b, c, Area
PRINT *, 'Welcome, please enter the &
&lengths of the 3 sides.'
READ *, a, b, c
PRINT *, 'Triangle''s area: ', Area(a,b,c)
END PROGRAM Triangle
当我使用gfortran
编译triangle1.f90
时,会收到以下错误信息:
triangle1.f90:16.25:
REAL :: a, b, c, Area
1
triangle1.f90:14.8:
USE Triangle_Operations
2
Error: Symbol 'area' at (1) conflicts with symbol from module 'triangle_operations', use-associated at (2)
triangle1.f90:19.13:
READ *, a, b, c
1
Error: Symbol 'a' at (1) has no IMPLICIT type
triangle1.f90:19.16:
READ *, a, b, c
1
Error: Symbol 'b' at (1) has no IMPLICIT type
triangle1.f90:19.19:
READ *, a, b, c
1
Error: Symbol 'c' at (1) has no IMPLICIT type
为什么变量a,b,c
会出现错误?我已经明确将它们定义为实数。
triangle1.f90
的文件。也许我需要更改扩展名,或者使用特定的编译器?我还不知道... - ShanZhengYang