포트란, 3차원 방정식 풀기(solve of 3rd simultaneous equation), Do문, IF문, open문 사용
Channel: Fortran Tutorial
Date: 03/02/2022

#Do-loop #if-then-else-if #open
      program linequ !js.ex_4_2.f95
      real a(1:99, 1:100), p
      integer i,j,k,n
      
      open(4,file='linequ2.dat',status='old')      
      read(4,1001) n
1001  format(i3)
      do 400, i=1,n,1
         read(4, 200)   (a(i,j), j=1,n+1,1)
         write(*,300) i,(a(i,j), j=1,n+1,1) 
200      format(10f10.0)         
300      format(i4,10f8.3:/(4x,10f8.3))
400   continue

      do 900, k=1,n,1
         p=a(k,k)
         do 500, j=k,n+1,1
500         a(k,j)=a(k,j)/p
      do 700, i=1,n,1
         if(i.ne.k)then
           p=a(i,k)
           do 600, j=k,n+1,1
600              a(i,j)=a(i,j)-p*a(k,j)
         endif
700  continue

     write(*,'(i3)')k
     do 800, i=1,n,1
800        write(*,300)i,(a(i,j),j=1,n+1,1)
900  continue
     
     write(*,1000)(i,a(i,n+1),i=1,n,1)
1000 format(' x(',i2,')=',f8.3)
     endprogram linequ                          

linequ2.data
  3
     2.000    -3.000     1.000    -1.000
     4.000     1.000    -3.000    -7.000
    -1.000     6.000    -2.000     5.000