Factorial in COBOL

Published on 18 April 2026 (Updated: 18 April 2026)

Welcome to the Factorial in COBOL page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

identification division.
program-id. factorial.

data division.
working-storage section.

01 cmd-args  pic x(38).
01 num       pic s9(7).
01 result    pic z(18)9 value 1.

procedure division.

main.
    accept cmd-args from command-line

    if function test-numval(cmd-args) not = 0
        perform show-usage
    end-if

    compute num = function numval(cmd-args)

    if num < 0
        perform show-usage
    end-if

    compute result = function factorial(num)
    display result

    stop run.

show-usage.
    display "Usage: please input a non-negative integer"
    stop run.

Factorial in COBOL was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.