Domanda

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?

È stato utile?

Soluzione

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))

Altri suggerimenti

One possible solution would be this:

do i=1,20,5                     
    x=0.0                 
    x=(sum(a(i:i+4)))
    write(*,*) x           
end do
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top