real :: a(-4:5)
a(-4) = 0.
a(-3) = 80.
a(-2) = 80.
a(-1) = 0.
a(0) = 0.
a(1) = 0.
a(2) = 80.
a(3) = 80.
a(4) = 80.
a(5) = 0.
风平老涡 发表于 2021-4-10 22:36
每一个分别赋值
[mw_shl_code=fortran,true]real :: a(-4:5)
xiaoxueji 发表于 2021-4-12 13:31
分别赋值这个角度顺序不是确定的吗
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
风平老涡 发表于 2021-4-12 22:01
那你需要的是随机赋值。
[mw_shl_code=fortran,true]program test
implicit none
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |