输出相应的值以及其他选择的值(DO Loops)

Output the corresponding value as well for the other chosen value (DO Loops)

PROGRAM ONE

REAL:: num1 = 200,num2 = 16,num3 = 10,num4
REAL:: counter,smallest

WRITE(*,*) "    Counter", "     num4"
WRITE(*,*) "    --------------------"
DO counter = 0.1,8,0.1
  num4 = (num1 * num2 * num3)/(counter * sqrt(num3**2 - counter**2))
  WRITE(*,*) counter,num4

  IF (counter == 0.1) THEN
     smallest = num4
  END IF

  IF (num4 < smallest) THEN
     smallest = num4
  END IF  

END DO
WRITE(*,*) "The smallest num4 is:", smallest

STOP
END PROGRAM ONE

程序需要运行明白我想表达的意思。

这会找到并显示最低的 num4 值。我还希望它显示的是 num4 值对应的 counter 值。该 counter 值将与最后一个 WRITE 语句一起使用。它应该说:

WRITE(*,*) "The smallest num4 is:", smallest, "for", counter

输出应该是:

The smallest num4 is 640.021 for 7.10000

声明一个新变量,保存num4中最小值对应的计数器值。

在您的程序顶部附近有:

REAL:: counter,smallest,smallCtr

然后在分配给 smallest 时在 IF 块中设置它:

IF (counter == 0.1) THEN
  smallest = num4
  smallCtr = counter
END IF

IF (num4 < smallest) THEN
  smallest = num4
  smallCtr = counter
END IF

然后你可以把它和smallest一起写出来:

WRITE(*,*) "The smallest num4 is:", smallest, "for", smallCtr