      program GaussJordan
      implicit real*8 (a-h,o-z)
      parameter (N=3)
      dimension a(N,N),b(N),x(N)
      
*******************************************
*     H METHODOS GAUSS-JORDAN             *
*******************************************
      a(1,1)= 3d0
      a(1,2)=-1d0
      a(1,3)= 2d0
      a(2,1)= 1d0
      a(2,2)= 2d0
      a(2,3)= 3d0
      a(3,1)= 2d0
      a(3,2)=-2d0
      a(3,3)=-1d0
      
      b(1) =12d0
      b(2) =11d0
      b(3) = 2d0
      print*, 'Oi arxikoi pinakes A(3x3) kai B(3x1):'
      print '(4f7.3)',a(1,1),a(1,2),a(1,3),b(1)
      print '(4f7.3)',a(2,1),a(2,2),a(2,3),b(2)
      print '(4f7.3)',a(3,1),a(3,2),a(3,3),b(3)
      print*
      print*, 'Patiste Enter gia sinexeia'
      pause      

      do k=1,N
         do i=1,N
            if (i.ne.k) then
               factor=a(i,k)/a(k,k)
               do j=1,N
                  a(i,j)=a(k,j)*factor-a(i,j)
               enddo
               b(i)=b(k)*factor-b(i)
            endif
         enddo
         print*, 'Oi pinakes A kai B meta apo prakseis:'
         print '(4f7.3)',a(1,1),a(1,2),a(1,3),b(1)
         print '(4f7.3)',a(2,1),a(2,2),a(2,3),b(2)
         print '(4f7.3)',a(3,1),a(3,2),a(3,3),b(3)
         print*
         print*, 'Patiste Enter gia sinexeia'
         pause
      enddo
      print*, 'O pinakas A exei ginei diagonios'       
      do i=1,N
         x(i)=b(i)/a(i,i)
      enddo
      
      print*,'H lisi tou sistimatos:'
      print'(f7.3)',x
      print*, 'Press enter to exit'
      pause
      end
