module a
implicit none
integer,allocatable::spin(:)
integer::M,l
end module a
program test
use a
implicit none
integer::i,n
real ::harvest
M=0
print *,\'input the length of the lain\'
read *,l
allocate (spin(l))
call random_number(harvest)
do i=1,l
n=int(l*harvest)
if(harvestl/2)then
spin(i)=1
else
spin(i)=-1
endif
enddo
call calculate_magnet
print \'(a,i5)\',\'the magnet of the lain is \',M
contains
subroutine calculate_magnet
use a
implicit none
allocate(spin(l))
do i=1,l
M=M spin(i)
enddo
end subroutine calculate_magnet
end program test
|