windows平臺下fortran編程求解算術平均值?

windows平臺下fortran編程求解算術平均值

給定一個數組

通過fortran編程

求這個數組的平均值

例如x=[1,2,3,4,5,6,7,8]

!=====================================

! fortran計算均值子程序

!=====================================

subroutine dy2003310

implicit none

integer::i,N

real*8::x(8)

real*8::average

x=[1,2,3,4,5,6,7,8]

!均值

average=0

N=size(x)

do i=1,N

average=average+x(i)

end do

average=average/N

print *, "average:",average

end subroutine dy2003310

工具/原料

codeblocks IDE編程環境

方法/步驟

關於codeblocks IDE的極速安裝

請參考< >

windows平臺下fortran編程求解算術平均值

測試的源代碼如下:

implicit none

integer::i,N

real*8::x(8)

real*8::average

x=[1,2,3,4,5,6,7,8]

!均值

average=0

N=size(x)

do i=1,N

average=average+x(i)

end do

average=average/N

print *, "average:",average

windows平臺下fortran編程求解算術平均值

編譯、運行結果如下:

windows平臺下fortran編程求解算術平均值

相關問題答案