Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在Fortran中会出现这些错误,比如1处的不可分类语句和意外垃圾等?_Fortran - Fatal编程技术网

为什么在Fortran中会出现这些错误,比如1处的不可分类语句和意外垃圾等?

为什么在Fortran中会出现这些错误,比如1处的不可分类语句和意外垃圾等?,fortran,Fortran,我刚开始使用Fortran,并试图编写一个基本程序,但却遇到了很多我不理解的错误。请检查以下内容。我提到了其他类似的问题,但没有用 program roots real a,b,c real disc real root1,root2 write (*,*) , "Please provide a, b and c" read (*,*) ,a,b,c disc = b**2 -4.0*a*c if dis

我刚开始使用Fortran,并试图编写一个基本程序,但却遇到了很多我不理解的错误。请检查以下内容。我提到了其他类似的问题,但没有用

    program roots

    real a,b,c
    real disc
    real root1,root2

    write (*,*) , "Please provide a, b and c"
    read (*,*) ,a,b,c
    disc = b**2 -4.0*a*c

    if disc < 0
    print *,"No real roots"

    else if disc = 0
    print *,"Equal roots"
    root1 = -b/2
    print *,"root is :" ,root1

    else 
    print *,"2 real roots"
    2*root1 = -b + sqrt(b**2 - 4.0*a*c)
    2*root2 = -b - sqrt(b**2 - 4.0*a*c)
    print *,"root 1 is:" , root1
    print *,"root 2 is:" , root2

    end roots

你的代码中有许多错误

首先:始终使用
implicit none
,否则未定义的变量可能具有难以调试的隐式数据类型

您的
如果。。如果
块有多个错误,则结束。比较两个代码

程序根
隐式无
真正的a,b,c
真实光盘
真正的根1,根2
打印*,“请提供a、b和c”
读(*,*)a、b、c
圆盘=b**2-4.0*a*c
如果(圆盘<0),则
打印*,“无实际根”
否则,如果(disc==0),则
打印*,“等根”
root1=-b/2
打印*,“根是:”,根1
其他的
打印*,“2个实根”
root1=(-b+sqrt(b**2-4.0*a*c))/2
root2=(-b-sqrt(b**2-4.0*a*c))/2
打印*,“根1为:”,根1
打印*,“根2为:”,根2
如果结束
结束程序