integer::N integer,allocatable::num(:,:) integer::dim,itr,offset character*32::cformat='(i0.3, i4.3)' read*,N allocate(num(N,N)) ! even offset = 0 do itr=1,N/2 dim = N-itr*2+1 do i=itr, itr+dim-1 num(i,itr) = offset+i end do offset = offset + dim do i=itr, itr+dim-1 num(N-itr+1,i) = offset + i end do offset = offset + dim do i=itr, itr+dim-1 num(N-i+1,N-itr+1) = offset + i end do offset = offset + dim do i=itr, itr+dim-1 num(itr,N-i+1) = offset + i end do offset=offset + dim - 1 end do if ( mod(N,2) .eq. 1) then num(N/2+1,N/2+1)=N*N end if write (cformat(7:8),'(i2)') N-1 print cformat,num end program