program conjgf
implicit none
real(8) a(6,6)
integer i1, i2
do i1 = 1,6
do i2 = 1,6
if (i1=i2) then
a(i1,i2) = 0.0d0
else
a(i1,i2) = i1+i2
end if
enddo
enddo
print*,a
read(*,*)
end program conjgf
Transpose 发表于 2022-4-8 17:06
i1==i2,判断相等
program conjgf
implicit none
real(8) a(6,6)
integer i1, i2
Forall(i1=1:6,i2=1:6) a(i1,i2)=merge(0,i1+i2,i1==i2)
write(*,'(*(6f7.2,/))') a
read(*,*)
end program conjgf
青衣巷 发表于 2022-4-9 08:27
Fortran 是个矢量化的语言,所以它应该比C代码简洁一些。
[mw_shl_code=fortran,true]program conjgf
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |