fortran编程题,已知一个5×5的整型数组X,编程统计并输出其中值为0的元素个数N
答案:1 悬赏:60 手机版
解决时间 2021-11-14 17:33
- 提问者网友:原来太熟悉了会陌生
- 2021-11-14 09:06
fortran编程题,已知一个5×5的整型数组X,编程统计并输出其中值为0的元素个数N
最佳答案
- 五星知识达人网友:千夜
- 2021-11-14 10:36
F90的程序:
program zero_count
implicit none
integer :: i, j, count = 0
integer, dimension(5,5) :: a
real :: u
! initializing array
do i = 1, 5
do j = 1, 5
if (i .eq. j) then
a(i,j) = 1
else
a(i,j) = 0
end if
end do
end do
! zero element counting
do i = 1, 5
do j = 1, 5
if (a(i,j) .eq. 0) then
count = count + 1
end if
end do
end do
write (*,'(a, i2)') 'zero count = ', count
end program zero_count运行结果:
zero count = 20
program zero_count
implicit none
integer :: i, j, count = 0
integer, dimension(5,5) :: a
real :: u
! initializing array
do i = 1, 5
do j = 1, 5
if (i .eq. j) then
a(i,j) = 1
else
a(i,j) = 0
end if
end do
end do
! zero element counting
do i = 1, 5
do j = 1, 5
if (a(i,j) .eq. 0) then
count = count + 1
end if
end do
end do
write (*,'(a, i2)') 'zero count = ', count
end program zero_count运行结果:
zero count = 20
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯