fortran if test

youtube 2016. 6. 5. 03:04

2016.06.05
[Question] 조건문 질문
a.txt
-------
200 3
180 4
220 8
-------

do i=1,3
if (a(i,1)>=200.and.a(i,1)<=250) then
print*, 'pass'
else if (a(i,2)>0.and.a(i,2)<3) then
print*, 'pass'
end if
end do

이렇게 조건을 하나씩 하는건 알겠는데,
두 조건을 한번에
a의 1열이 200<a<250이고, 2열이 0<a<3 일 때
 print*, 'pass'를 하려면 어떻게 해야되나요?

if ((a(i,1)>=200.and.a(i,1)<=250).and. (a(i,2)>0.and.a(i,2)<3)) then
print*,'pass'

위에처럼 해봤지만 -Syntax error - unbalanced parentheses 가 나와서요 ...


---------------------------------------------------------------------

[solution]
gfortran 에서 테스트시에는 정상적으로 컴파일됨.
(질문에서 사용하는 포트란 컴파일 툴에 대한 언급이 안되어 있음)


pass 결과가 나오려면
a.txt 파일을 아래처럼 200 3 을 200 2 로 수정하면 됨.

a.txt
-------
200 2
180 4
220 8
-------



------------------------------------------------------------------

ifpass.zip





'youtube' 카테고리의 다른 글

python34 poly_1 inputPoly function  (0) 2016.06.12
python34 A variable number of arguments  (0) 2016.06.12
python27 pygame install  (0) 2016.06.12
python sorted  (0) 2016.06.12
python3.x pong game paddle width reduce  (0) 2016.06.01
: