FUNCTION Triangular_Nos(n) IMPLICIT NONE INTEGER, INTENT(IN) :: n INTEGER, DIMENSION(n) :: Triangular_Nos INTEGER :: i Triangular_Nos(1) = 1 DO i = 2, n Triangular_Nos(i) = Triangular_Nos(i-1) + i END DO END FUNCTION Triangular_Nos PROGRAM Blob IMPLICIT NONE INTERFACE FUNCTION Triangular_Nos(n) INTEGER, INTENT(IN) :: n INTEGER, DIMENSION(n) :: Triangular_Nos END FUNCTION Triangular_Nos END INTERFACE PRINT*, Triangular_Nos(23) ! etc END
gives:
1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276