IDENTIFICATION DIVISION.
PROGRAM-ID. EXERONE.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NumberArray.
02 numInteger PIC 9 OCCURS 5 TIMES.
77 COUNTER PIC 9 VALUE 1.
77 SECONDCOUNTER PIC 9 VALUE 1.
77 THIRDCOUNTER PIC 9 VALUE 1.
77 EXITED PIC 9 VALUE 0.
77 CHOICE PIC 9.
77 LARGESTNUM PIC 9.
77 FACTORIALRESULT PIC 999999 VALUE 1.
PROCEDURE DIVISION.
PERFORM PMENU UNTIL EXITED = 1.
STOP RUN.
PMENU.
DISPLAY " MENU ".
DISPLAY "[1] Fill array ".
DISPLAY "[2] Print Array ".
DISPLAY "[3] Factorial of Largest Number ".
DISPLAY "[4] Exit ".
DISPLAY " Choice : " WITH NO ADVANCING.
ACCEPT CHOICE.
IF CHOICE = 1
MOVE 1 TO COUNTER
PERFORM AcceptInputs UNTIL COUNTER > 5
ELSE
IF CHOICE = 2
MOVE 1 TO SECONDCOUNTER
PERFORM PrintLoop UNTIL SECONDCOUNTER > 5
DISPLAY " "
ELSE
IF CHOICE = 3
MOVE 1 TO THIRDCOUNTER
MOVE 0 TO LARGESTNUM
MOVE 1 TO FACTORIALRESULT
PERFORM LargestNumFactorial
DISPLAY FACTORIALRESULT
ELSE
IF CHOICE = 4
DISPLAY " Goodbye "
MOVE 1 TO EXITED
ELSE
DISPLAY " INVALID CHOICE "
END-IF
END-IF
END-IF
END-IF.
PrintLoop.
DISPLAY numInteger(SECONDCOUNTER) " " WITH NO ADVANCING
ADD 1 TO SECONDCOUNTER.
AcceptInputs.
DISPLAY " Enter positive integer: " WITH NO ADVANCING
ACCEPT numInteger(COUNTER)
IF numInteger(COUNTER) > 0
IF numInteger(COUNTER) < 10
ADD 1 TO COUNTER
ELSE
DISPLAY " One-digit positive integers only "
END-IF
ELSE
DISPLAY " One-digit positive integers only "
END-IF.
GetLargestNum.
IF numInteger(THIRDCOUNTER) > LARGESTNUM
MOVE numInteger(THIRDCOUNTER) TO LARGESTNUM
END-IF.
ADD 1 TO THIRDCOUNTER.
FactorialProcess.
MULTIPLY FACTORIALRESULT BY LARGESTNUM GIVING FACTORIALRESULT
SUBTRACT 1 FROM LARGESTNUM
SUBTRACT 1 FROM THIRDCOUNTER.
LargestNumFactorial.
PERFORM GetLargestNum UNTIL THIRDCOUNTER > 5
DISPLAY LARGESTNUM
MOVE LARGESTNUM TO THIRDCOUNTER
PERFORM FactorialProcess UNTIL THIRDCOUNTER = 0.