OK, there's a lot going on here, especially as the Fortran style you are using is a little archaic. Let's do it by steps ...
Firstly make sure you always use implicit none
Secondly if you know the size of the array a priori you can use a symbolic constant to denote its size. You do this via a parameter:
Program prog
Implicit None ! ALWAYS USE THIS
Integer, Parameter :: num = 36
Double Precision x( num )
Double Precision test
Double Precision v
Call Random_number( x )
v = test( x, num )
Write( *, * ) v
End Program prog
Function test( x, num )
Implicit None ! ALWAYS USE THIS
Double Precision test
Integer num
Double Precision x( num )
Integer i
test = 0.0d0
Do i = 1, num
test = test + x( i ) * x( i )
End Do
End Function test
[luser@cromer stackoverflow]$ gfortran -O -std=f95 -Wall -Wextra -pedantic func.f90
[luser@cromer stackoverflow]$ ./a.out
12.129812171430215
Note how num is set to be 36, but the parameter bit means I can not change its value - it is a constant and so can be used to set the size of arrays.
And that is how things stood until 1990. Then a number of things came into the language which change the answer. Most directly connected to your question are allocatable arrays, which allow you to specify the size of the array at run time, and assumed shape arrays, which make passing arrays to subprograms simpler. However a whole slew of other things came in and I suggest you have a look in a book to learn about them - the new language is much more expressive and safer than the old. As an example I would write the above nowadays as something like
[luser@cromer stackoverflow]$ cat func.f90
Module numbers_module
Integer, Parameter :: wp = Selected_real_kind( 12, 70 )
End Module numbers_module
Module funcs_module
Use numbers_module
Implicit None
Public :: test
Private
Contains
Function test( x ) Result( sum_sq )
Implicit None ! ALWAYS USE THIS
Real( wp ) :: sum_sq
Real( wp ), Dimension( : ), Intent( In ) :: x
sum_sq = Sum( x * x )
End Function test
End Module funcs_module
Program prog
Use numbers_module
Use funcs_module
Implicit None ! ALWAYS USE THIS
Real( wp ), Dimension( : ), Allocatable :: x
Real( wp ) :: v
Integer :: num
Write( *, * ) 'How many elements ?'
Read ( *, * ) num
Allocate( x( 1:num ) )
Call Random_number( x )
v = test( x )
Write( *, * ) v
End Program prog
[luser@cromer stackoverflow]$ gfortran -O -std=f95 -Wall -Wextra -pedantic func.f90
[luser@cromer stackoverflow]$ ./a.out
How many elements ?
39
14.151818513394156
If you decide to go this way make sure you understand why to use this method an interface to test needs to be in scope at the calling point - and to do this read a book.
Oh. Common. Just Say No.
double precisionshould avoided and changed toreal(rp), whererpmight berp=kind(1d.0)for simplicity or you useselected_real_kind.Also, indent tour code!