      program minnedr

      integer n,i,j
      real a(10,10),b(10)
      real l(10,10),u(10,10),x(10)
      
      write (*,*)"Az matrix sorainak a szama: n="
      read(*,*)n
      do i=1,n
	 do j=1,n
         write(*,*)"Az A matrix (",i,",",j,")-dik eleme :"
	 read(*,*)a(i,j)
         enddo
      enddo
      do i=1,n
         write(*,*)"A b vektor",i,"-dik eleme:"
	 read(*,*)b(i)
      enddo

      call lulu(n,a,b,c,l,u,x)
      do i=1,n
	 do j=1,n
         write(*,*)"Az L matrix (",i,",",j,")-dik eleme :"
	 write(*,*)l(i,j)
         enddo
      enddo
      do i=1,n
	 do j=1,n
         write(*,*)"Az U matrix (",i,",",j,")-dik eleme :"
	 write(*,*)u(i,j)
         enddo
      enddo
      do i=1,n
         write(*,*)"A x vektor",i,"-dik eleme:"
	 write(*,*)x(i)
      enddo
      write(*,*)c

      stop
      end
      
      subroutine lulu(n,a,b,c,l,u,x)
      integer n
      real a(10,10),b(10)
      integer c
      real l(10,10),u(10,10),x(10)
      integer i,j,k
      real s,r(10),y(10),d(10)
      do 101 i=1,n
      s=b(i)
       do 102 j=1,n
       r(j)=a(i,j)
102    continue
      do 103 k=1,i-1
      l(i,k)=r(k)
      s=s-y(k)*l(i,k)
       do 104 j=k+1,n
       r(j)=r(j)-l(i,k)*u(k,j)
104   continue
103   continue
      if (r(i) .eq. 0.0) goto 1
      d(i)=1/r(i)
      l(i,i)=r(i)
      u(i,i)=1
      do 105 j=i+1,n
      u(i,j)=r(j)*d(i)
105   continue
      y(i)=s*d(i)
101   continue
      do 106 i=n,1,-1
      s=y(i)
      do 107 j=i+1,n
      s=s-u(i,j)*y(j)
107   continue
      y(i)=s
      x(i)=s
106   continue
      goto 2
1     write(*,20)
20    format(1x,'Szingularis a matrix!')
      c=1
2     continue
      return
      end
