program sedl
implicit none
interface
subroutine find_sedl(A,B,kol)
real, intent(in), dimension(:,:) :: A
integer, intent(out), dimension(:,:) :: B
integer, intent(out) :: kol
end subroutine find_sedl
end interface
integer i, m, n, kol
real, allocatable, dimension(:,:) :: A
integer, allocatable, dimension(:,:) :: B
open(1,file="In.txt")
open(2,file="out.txt")
do
read(1,*,end=45)m,n
allocate(A(1:m,1:n),B(2,m*n/2))
read(1,*)(A(i,:),i=1,m)
write(2,5)(A(i,:),i=1,m)
call find_sedl(A,B,kol)
write(2,6)kol,(B(1,i),i=1,kol),(B(2,i),i=1,kol),(A(B(1,i),B(2,i)),i=1,kol)
6 format('Количество седловых элементов:'/i4/'их координаты и значения:'/'| x |'&
<kol>(i6,'|')/'| y |'<kol>(i6,'|')/'|A(x,y)|'<kol>(f6.2,'|'))
5 format('Исходная мтрица'/<n>(f8.2))
deallocate(A,B)
end do
45 end program sedl
subroutine find_sedl(A,B,kol)
implicit none
real, intent(in), dimension(:,:) :: A
integer, intent(out), dimension(:,:) :: B
integer, intent(out) :: kol
integer i,j,m,n
kol=0
m=size(A,dim=1)
n=size(A,dim=2)
do i=1,m
do j=1,n
if (i>1 .and. i<m .and. j>1 .and. j<n .and. A(i,j)<A(i,j-1) .and. A(i,j)<A(i,j+1)&
.and. A(i,j)>A(i-1,j) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (i==1) then
if(j==1 .and. A(i,j)<A(i,j+1) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (j==n .and. A(i,j)<A(i,j-1) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (A(i,j)<A(i,j+1) .and. A(i,j)<A(i,j-1) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
end if
elseif (i==m) then
if(j==1 .and. A(i,j)<A(i,j+1) .and. A(i,j)>A(i-1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (j==n .and. A(i,j)<A(i,j-1) .and. A(i,j)>A(i-1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (A(i,j)<A(i,j+1) .and. A(i,j)<A(i,j-1) .and. A(i,j)>A(i-1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
end if
elseif (j==1 .and. A(i,j)<A(i,j+1) .and. A(i,j)>A(i-1,j) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
elseif (j==n .and. A(i,j)<A(i,j-1) .and. A(i,j)>A(i-1,j) .and. A(i,j)>A(i+1,j)) then
kol=kol+1
B(1,kol)=i;B(2,kol)=j
end if
end do
end do
end subroutine

Исходная мтрица
12.00 20.00 3.00 15.00 9.00
11.00 5.00 32.00 7.00 8.00
1.00 4.00 5.00 -7.00 2.00
3.00 7.00 6.00 8.00 7.00
Количество седловых элементов:
5
их координаты и значения:
| x | 1| 1| 4| 4| 4|
| y | 1| 5| 1| 3| 5|
|A(x,y)| 12.00| 9.00| 3.00| 6.00| 7.00|
Исходная мтрица
1.00 -13.00 4.00 -8.00
6.00 -6.00 7.00 7.00
3.00 -15.00 67.00 8.00
Количество седловых элементов:
2
их координаты и значения:
| x | 2| 3|
| y | 2| 4|
|A(x,y)| -6.00| 8.00|
Соседние файлы в папке реализация нахождения седлового элемента на фортране с использованием внешних подпрограмм-функций