program main implicit none integer :: ii,i,n,nc,sa,j integer, allocatable :: a(:),b(:) real*8, allocatable :: c(:,:) character*20 :: input !1) write(*,*) 'Name of input file' read(*,*) input open(10,file=input) read(10,*) n allocate(a(n)) do i=1,n read(10,*) a(i) enddo close(10) !2) if (mod(n,2).eq.0) then nc=n/2 else nc=n/2+1 endif allocate(b(nc)) ii=0 do i=1,n,2 ii=ii+1 b(ii)=a(i) enddo call bubble (b,nc) sa=0 do i=2,n,2 sa=sa+a(i) enddo write(*,*) 'Sum is', sa !3) allocate(c(n,n)) if (sa.gt.0) then do i=1,n do j=1,n c(i,j)=a(i)+i**2 enddo enddo else do i=1,n c(i,i)=a(i) enddo do i=1,n do j=i+1,n c(i,j)=dble(sa)/dble(i+j) c(j,i)=c(i,j) enddo enddo endif !4) open(11,file='b.dat') open(12,file='c.dat') do i=1,nc write(11,100) i, b(i) enddo do i=1,n do j=1,n write(12,101) i,j,c(i,j) enddo enddo close(11) close(12) 100 format(2(I5)) 101 format(2(I5),F10.5) stop end program main subroutine bubble(c,n) implicit none integer, intent(in) :: n integer, intent(inout) :: c(n) integer :: i,j do i=1,n do j=n,i+1,-1 if (c(j-1).lt.c(j)) then call swap(c(j-1),c(j)) endif enddo enddo return end subroutine bubble subroutine swap(x,y) implicit none integer, intent(inout) :: x,y integer :: tmp tmp=x x=y y=tmp return end subroutine swap