program matrix
implicit none
integer :: row,col,i,j,temp
real,allocatable :: A(:,:),b(:),Q(:)
write(*,*) "enter size of row/ col"
read (*,*) row,col
allocate(A(row,col+1))
allocate(b(row))
allocate(Q(col+1))
do i=1,row
do j=1,col
write(*,*) "A(",i,j,")="
read (*,*) A(i,j)
enddo
enddo
do i=1,row
write(*,*) "b(",i,")="
read (*,*) A(i,col+1)
enddo
do i=1,row
write(*,*) A(i,:)
enddo
write(*,*) "-----------------Gauss-----------------------"
do i=1,row
if(A(i,i)==0)then
temp=0
do j=i+1,row
if(A(j,i)/=0)then
Q=A(i,:)
A(i,:)=A(j,:)
A(j,:)=Q
temp=1
endif
enddo
if(temp==0)then
write(*,*)"Not Good!!"
stop
endif
endif
do j=1,row
if(i/=j)then
A(j,:)=(-1)*(A(j,i)/A(i,i))*A(i,:)+A(j,:)
endif
enddo
do j=1,row
if(i/=j)then
A(j,:)=(-1)*(A(j,i)/A(i,i))*A(i,:)+A(j,:)
endif
enddo
沒有留言:
張貼留言