Factorial in Fortran

Example for versions Intel Visual Fortran 11.1, gfortran 4.5.0

This example uses iterative factorial definition. Format specifiers I and A are used for printing integers and strings, respectively. Trying to calculate 13! produces an arithmetic overflow error, so last lines of program output look like this:

13! = 1932053504
14! = 1278945280
15! = 2004310016
16! = 2004189184

    program Factorial

    integer :: f,n

    f = 1
    n = 0
    
    do
        print '(I2, A, I10)', n, "! = ", f
        n = n + 1
        f = f * n
        if (n==17) then
            exit
        end if
    end do

    end program Factorial