-------------------------------------------------------------------------------------------------------------------------------------
PROGRAM toomas
IMPLICIT NONE
INTEGER::n,i,j,k,l
REAL::landa
REAL,ALLOCATABLE::a(:,:),r(:),x(:)
PRINT*
PRINT*," _ _"
PRINT*," | | | "
PRINT*," 1 | b(1) c(1) 0 0 0 . 0 | r(1) | "
PRINT*," | | |"
PRINT*," 2 | a(2) b(2) c(2) 0 0 . 0 | r(2) | "
PRINT*," | | |"
PRINT*," 3 | 0 a(3) b(3) c(3) 0 . 0 | r(3) | "
PRINT*," | | |"
PRINT*," . | 0 0 a(4) b(4) . . . | r(4) | "
PRINT*," . | | | "
PRINT*," . | . . . . . . 0 | . | "
PRINT*," . | | | "
PRINT*," . | . . . . . . c(n) | . | "
PRINT*," | | |"
PRINT*," n | 0 0 0 . 0 a(n) b(n) | r(n) | "
PRINT*," |_ | _| "
PRINT*," (n , n+1)"
PRINT*
PRINT*,"-----------------------------------------------------------------"
PRINT*
PRINT*," n ya tedad moadelat ra vared konid : "
READ*,n
ALLOCATE (a(n,n),r(n),x(n))
PRINT*
PRINT*," b( 1 ) va c( 1 ) ra be tartib vared konid :"
READ*,a(1,1),a(1,2)
DO i=2,n-1
PRINT*," a(",i,") , b(",i,") , c(",i,") ra be tartib vared konid : "
READ*,a(i,i-1:i+1)
END DO
PRINT*," a(",n,") va b(",n,") ra be tartib vared konid : "
READ*,a(n,n-1),a(n,n)
PRINT*
PRINT*," r(1) ta r(",n,") ra be tartib vared konid : "
READ*,r(1:n)
PRINT*
PRINT*,"------------------------------------------------------------------"
PRINT*
DO j=1,n-1
landa=-a(j+1,j)/a(j,j)
a(j+1,j)=0
a(j+1,j+1)=(a(j,j+1)*landa)+a(j+1,j+1)
r(j+1)=(landa*r(j))+r(j+1)
END DO
x(n)=r(n)/a(n,n)
DO k=n,1,-1
x(k)=(r(k)-(a(k,k+1)*x(k+1)))/a(k,k)
END DO
DO l=1,n
PRINT*," X(",l,") = ",x(l)
END DO
PRINT*
END