看板 Fortran 關於我們 聯絡資訊
在練習寫一元二次方程式,參考網路別人的寫法的程式碼如下: real a, b, c, det complex r1, r2 1 write (*, "(/'請輸入方程式 ax^2+bx+c=0 的 a, b, c 值: ', $)") read (*, *) a, b, c if (a == 0.) then print *, 'a 不可為 0' go to 1 end if det = b**2 - 4.*a*c if (det) 3, 5, 7 3 r1 = cmplx(-b/(2.*a), sqrt(-det)/(2.*a)) r2 = cmplx(-b/(2.*a), -sqrt(-det)/(2.*a)) print *, '無實數根, 有 2 個複數根:', r1, r2 go to 1 5 print *, '有 1 個實數根:', -b/(2.*a) go to 1 7 print *, '有 2 個實數根:', (-b+sqrt(det))/(2.*a), (-b-sqrt(det))/(2.*a) go to 1 end 來源:https://tw.answers.yahoo.com/question/index?qid=20091226000015KK08689 想請問他的if 怎麼判斷式只有一個變數,後面接3 5 7就可以 他怎麼知道det<0要去3,det==要去5,det>0要去7 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.121.208.62 ※ 文章網址: https://www.ptt.cc/bbs/Fortran/M.1463068715.A.516.html
kerwinhui: arithmetic if,現在很少人用了 05/13 10:41
kerwinhui: 最原始版fortran只有這種if,但有了logical if以後大家 05/13 10:44
kerwinhui: 都比較常用好讀又好寫的logical if,Fortran90已經把 05/13 10:45
kerwinhui: arithmetic if列為obsolescent了,留著只是為了和F77相 05/13 10:47
kerwinhui: 容 05/13 10:47
rex0707: 長知識推 05/13 12:30
afe812: 謝謝 05/16 18:07