主题:请大家帮忙看下问题出在哪里?
本人刚接触fortran,用CVF6.5,建立项目“fortran console application”然后建立文件“fortran free format source file”。编写了程序后(见文章末尾),发现出现以下错误
--------------------Configuration: 061901 - Win32 Debug--------------------
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: This name does not have a type, and must have an explicit type. [DISCRIMINANT]
imag_part=sqrt(abs(discriminant))/(2.*a)
---------------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Warning: Arguments' data types are incompatible with intrinsic procedure, assume EXTERNAL. [ABS]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: This name does not have a type, and must have an explicit type. [ABS]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: The data types of the argument(s) are invalid. [SQRT]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
Error executing df.exe.
061901.exe - 3 error(s), 1 warning(s)
请问原因是什么?如何解决?
project program roots
implicit none
real :: a
real :: b
real :: c
real :: dis
real :: imag_part
real :: real_part
real :: x1
real :: x2
write (*,*) 'this program solves for the roots of a quadratic'
write (*,*) 'equation of the form A*X**2+B*X+C=0.'
write (*,*) 'enter the coefficients A,B,and C:'
read (*,*) a, b, c
write (*,*) 'the coefficients A,B,C are:',a, b, c
dis=b**2-4.*a*c
if (dis>0.) then
x1=(-b+sqrt(dis))/(2.*a)
x2=(-b-sqrt(dis))/(2.*a)
write (*,*) 'this equation has two real roots:'
write (*,*) 'x1=',x1
write (*,*) 'x2=',x2
else if (dis==0.) then
x1=(-b)/(2.*a)
write (*,*) 'this equation has two identical real roots:'
write (*,*) 'x1=x2=',x1
else
real_part=(-b)/(2.*a)
imag_part=sqrt(abs(discriminant))/(2.*a)
write (*,*) 'this equation has two complex roots:'
write (*,*) 'x1= ',real_part,'+i',imag_part
write (*,*) 'x2= ',real_part,'-i',imag_part
end if
end program roots
--------------------Configuration: 061901 - Win32 Debug--------------------
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: This name does not have a type, and must have an explicit type. [DISCRIMINANT]
imag_part=sqrt(abs(discriminant))/(2.*a)
---------------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Warning: Arguments' data types are incompatible with intrinsic procedure, assume EXTERNAL. [ABS]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: This name does not have a type, and must have an explicit type. [ABS]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\My Projects\061901.f90(37) : Error: The data types of the argument(s) are invalid. [SQRT]
imag_part=sqrt(abs(discriminant))/(2.*a)
-----------------^
Error executing df.exe.
061901.exe - 3 error(s), 1 warning(s)
请问原因是什么?如何解决?
project program roots
implicit none
real :: a
real :: b
real :: c
real :: dis
real :: imag_part
real :: real_part
real :: x1
real :: x2
write (*,*) 'this program solves for the roots of a quadratic'
write (*,*) 'equation of the form A*X**2+B*X+C=0.'
write (*,*) 'enter the coefficients A,B,and C:'
read (*,*) a, b, c
write (*,*) 'the coefficients A,B,C are:',a, b, c
dis=b**2-4.*a*c
if (dis>0.) then
x1=(-b+sqrt(dis))/(2.*a)
x2=(-b-sqrt(dis))/(2.*a)
write (*,*) 'this equation has two real roots:'
write (*,*) 'x1=',x1
write (*,*) 'x2=',x2
else if (dis==0.) then
x1=(-b)/(2.*a)
write (*,*) 'this equation has two identical real roots:'
write (*,*) 'x1=x2=',x1
else
real_part=(-b)/(2.*a)
imag_part=sqrt(abs(discriminant))/(2.*a)
write (*,*) 'this equation has two complex roots:'
write (*,*) 'x1= ',real_part,'+i',imag_part
write (*,*) 'x2= ',real_part,'-i',imag_part
end if
end program roots