program main implicit none integer :: n,nc,nd,ntmp integer, allocatable :: a(:),b(:),c(:) integer :: i,k !1) open(10,file='input') read(*,*) n if (n.lt.3) then write(*,*) 'n must be => 3' stop endif allocate(a(n)) read(*,*) a !2) if (mod(n,2).eq.0) then nc=n-2 allocate(b(nc)) write(*,*) 'n is even' do i=1,n-2 b(i)=a(i)+a(i+2) enddo else allocate(b(n)) write(*,*) 'n is odd' do i=1,n b(i)=a(n+1-i)**3 enddo endif !3) if (mod(n,2).eq.0) then ntmp=nc else ntmp=n endif nd=0 do i=1,ntmp if (b(i).lt.0) nd=nd+1 enddo if (nd.gt.0) then allocate(c(nd)) k=0 do i=1,ntmp if (b(i).lt.0) then k=k+1 c(k)=b(i) endif enddo write(*,*) 'Sum of c elements',sum(c) endif !4) open(11,file='b.dat') if (mod(n,2).eq.0) then do i=1,nc write(11,100) i,b(i) enddo else do i=1,n write(11,100) i,b(i) enddo endif if (nd.gt.0) then open(12,file='c.dat') do i=1,nd write(12,100) i,c(i) enddo close(12) else write(*,*) 'No negative elements in c' endif 100 format(2(I6)) deallocate(a) deallocate(b) if (nd.gt.0) deallocate(c) close(10) close(11) stop end program main