電子書籍の厳選無料作品が豊富!

以下のコードで、xとthetaに5,5と入力しても、出力が5となってしまいます。500になってほしかったんですが・・・
どこが悪いのか教えて下さい。
-----------------------------------------------
read(5,*)x,theta
if(0.0d0.LE.x.LE.4.0d0) then
eta=theta
go to 20
else if(4.0d0.LT.x.LT.7.0d0) then
eta=100.0d0*theta
go to 20
else if(7.0d0.LE.x.LE.10.0d0) then
eta=sqrt(3.0d0*sqrt(2.0d0))*theta
go to 20
end if

20write(6,30) eta
30format(F10.5)
stop
end
-----------------------------------

A 回答 (1件)

read(5,*)x,theta



! you cannot write 0 < x < 4
! you need to write 0 < x and x < 4
! to get intended behavior
! the two codes have the different meanings.

! tested with g95 compiler

if(0.0d0 .LE. x .and. x .LE.4.0d0) then
eta=theta
go to 20
else if(4.0d0.LT. x .and. x .LT.7.0d0) then
eta=100.0d0*theta
go to 20
else if(7.0d0.LE. x .and. x .LE.10.0d0) then
eta=sqrt(3.0d0*sqrt(2.0d0))*theta
go to 20
end if

20 write(6,30) eta
30 format(F10.5)
stop
end
    • good
    • 0
この回答へのお礼

できました♪
ありがとうございます。

if(0.0d0 .LE. x .and. x .LE.4.0d0) then
eta=theta
go to 20
else if(x .LT.7.0d0) then
eta=100.0d0*theta
go to 20
else if(x .LE.10.0d0) then
eta=sqrt(3.0d0*sqrt(2.0d0))*theta
go to 20
end if
でもいけることがわかりました!!
ありがとうございます☆

お礼日時:2008/06/27 19:46

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!