Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program esep
integer n,i,j,k
real a(10,10),b(10,10),c(10,10),d(10),x(10),y(10),sum,sum1
print*, "Enter the size of matrix"
read*,n
do i=1,n
print*," Enter the first matrix row by row"
read*, (a(i,j), j=1,n)
end do
do i=1,n
do j=1,n
b(i,j)=0
c(i,j)=0
end do
end do
do i=1,n
b(i,1)=a(i,1)
c(i,i)=1
end do
do j=1,n
c(1,j)=a(1,j)/b(1,1)
end do
do i=1,n
do j=1,n
if(i>=j .and. j>1) then
sum=0
do k=1,j-1
sum=sum+(b(i,k)*c(k,j))
end do
b(i,j)=a(i,j)-sum
end if
if(i>1 .and. i<j) then
sum1=0
do k=1,i-1
sum1=sum1+(b(i,k)*c(k,j))
end do
c(i,j)=(a(i,j)-sum1)/(b(i,i))
end if
end do
end do
do i=1,n
end do
do i=1,n
end do
print*, "Enter the coefficients"
do i=1,n
read*, d(i)
end do
y(1)=d(1)/b(1,1)
do i=2,n
sum=0
do k=1,i-1
sum=sum+(b(i,k)*y(k))
end do
y(i)=(d(i)-sum)/(b(i,i))
end do
x(n)=y(n)
do i=n-1,1,-1
sum1=0
do k=i+1,n
sum1=sum1+(c(i,k)*x(k))
end do
x(i)=y(i)-sum1
end do
do i=1,n
print*,"x is ",(x(i))
end do
end program esep
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more