In Fortran 90, do array dimensions have to be declared beforehand?

You want to use allocatable arrays:

PROGRAM mytest
  IMPLICIT NONE
  INTEGER :: i, j, k, mysum
  REAL, DIMENSION(:,:), allocatable :: c   !<-  c is allocatable, rank 2

  ! Let array c be a k-by-k**2 array
  ! Determine k within the program by some means...for example,
  mysum=0
  DO i=1, 3
    mysum=mysum+1
  END DO
  k=mysum

  WRITE(*,*) "k=", k
  WRITE(*,*) "k**2=", k**2
  WRITE(*,*)

  allocate(c(k,k**2))                  ! <-- allocate array c with supplied shape

  DO i=1,size(c,1)
    WRITE(*,"(100(3X,F3.1))") (c(i,j), j=1,size(c,2))
  END DO

  deallocate(c)                        ! <-- deallocate when done
END PROGRAM mytest