本帖最后由 风平老涡 于 2021-4-12 22:20 编辑
那你需要的是随机赋值。
[Fortran] 纯文本查看 复制代码 program test
implicit none
real :: a(-4:5), r
integer :: i, k=0, m = 0
call random_seed
do i = -4, 5
call random_number(r)
if(r > 0.5 .and. k < 5) then
a(i) = 0.
k = k + 1
elseif(m < 5) then
a(i) = 80.
m = m + 1
else
a(i) = 0.
end if
end do
print *, a
end program test
运行俩次结果
0.00000000 0.00000000 80.0000000 0.00000000 80.0000000 80.0000000 80.0000000 80.0000000 0.00000000 0.00000000
0.00000000 0.00000000 80.0000000 0.00000000 0.00000000 80.0000000 80.0000000 80.0000000 0.00000000 80.0000000
|