문제

I have an array like this :

1717.531
1717.364
1716.725
1716.723
1716.536
1716.304
1716.221
1715.998
1715.799
1715.702
1715.648
1715.254
1715.186
1714.733
1714.532
1714.266
1714.223
1714.094
1713.943
1713.873
1713.803
1713.578

I want to SUM each 5 elements separately, which function to use and how?

도움이 되었습니까?

해결책

You could use a loop with a step size:

do i=1, N, 5

Then the intrinsic function sum applied to slices of the array:

sum (a(i: i+4))

다른 팁

One possible solution would be this:

do i=1,20,5                     
    x=0.0                 
    x=(sum(a(i:i+4)))
    write(*,*) x           
end do
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top