Example 1 - XL Fortran Source File

      PROGRAM CALCULATE
!
! Program to calculate the sum of up to n values of x**3
! where negative values are ignored.
!
      IMPLICIT NONE
      INTEGER I,N
      REAL SUM,X,Y
      READ(*,*) N
      SUM=0
      DO I=1,N
         READ(*,*) X
         IF (X.GE.0) THEN
            Y=X**3
            SUM=SUM+Y
         END IF
      END DO
      WRITE(*,*) 'This is the sum of the positive cubes:',SUM
      END

Execution Results

Here is what happens when you run the program:


$ a.out
5
37
22
-4
19
6
 This is the sum of the positive cubes:  68376.00000
IBM Copyright 2003