fork download
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. EXERONE.
  3.  
  4. ENVIRONMENT DIVISION.
  5.  
  6. DATA DIVISION.
  7. WORKING-STORAGE SECTION.
  8. 01 NumberArray.
  9. 02 numInteger PIC 9 OCCURS 5 TIMES.
  10. 77 COUNTER PIC 9 VALUE 1.
  11. 77 SECONDCOUNTER PIC 9 VALUE 1.
  12. 77 THIRDCOUNTER PIC 9 VALUE 1.
  13. 77 EXITED PIC 9 VALUE 0.
  14. 77 CHOICE PIC 9.
  15. 77 LARGESTNUM PIC 9.
  16. 77 FACTORIALRESULT PIC 999999 VALUE 1.
  17.  
  18.  
  19. PROCEDURE DIVISION.
  20. PERFORM PMENU UNTIL EXITED = 1.
  21. STOP RUN.
  22. PMENU.
  23. DISPLAY " MENU ".
  24. DISPLAY "[1] Fill array ".
  25. DISPLAY "[2] Print Array ".
  26. DISPLAY "[3] Factorial of Largest Number ".
  27. DISPLAY "[4] Exit ".
  28. DISPLAY " Choice : " WITH NO ADVANCING.
  29. ACCEPT CHOICE.
  30. IF CHOICE = 1
  31. MOVE 1 TO COUNTER
  32. PERFORM AcceptInputs UNTIL COUNTER > 5
  33. ELSE
  34. IF CHOICE = 2
  35. MOVE 1 TO SECONDCOUNTER
  36. PERFORM PrintLoop UNTIL SECONDCOUNTER > 5
  37. DISPLAY " "
  38. ELSE
  39. IF CHOICE = 3
  40. MOVE 1 TO THIRDCOUNTER
  41. MOVE 0 TO LARGESTNUM
  42. MOVE 1 TO FACTORIALRESULT
  43. PERFORM LargestNumFactorial
  44. DISPLAY FACTORIALRESULT
  45. ELSE
  46. IF CHOICE = 4
  47. DISPLAY " Goodbye "
  48. MOVE 1 TO EXITED
  49. ELSE
  50. DISPLAY " INVALID CHOICE "
  51. END-IF
  52. END-IF
  53. END-IF
  54. END-IF.
  55.  
  56. PrintLoop.
  57. DISPLAY numInteger(SECONDCOUNTER) " " WITH NO ADVANCING
  58. ADD 1 TO SECONDCOUNTER.
  59.  
  60. AcceptInputs.
  61. DISPLAY " Enter positive integer: " WITH NO ADVANCING
  62. ACCEPT numInteger(COUNTER)
  63. IF numInteger(COUNTER) > 0
  64. IF numInteger(COUNTER) < 10
  65. ADD 1 TO COUNTER
  66. ELSE
  67. DISPLAY " One-digit positive integers only "
  68. END-IF
  69. ELSE
  70. DISPLAY " One-digit positive integers only "
  71. END-IF.
  72.  
  73. GetLargestNum.
  74. IF numInteger(THIRDCOUNTER) > LARGESTNUM
  75. MOVE numInteger(THIRDCOUNTER) TO LARGESTNUM
  76. END-IF.
  77. ADD 1 TO THIRDCOUNTER.
  78.  
  79. FactorialProcess.
  80. MULTIPLY FACTORIALRESULT BY LARGESTNUM GIVING FACTORIALRESULT
  81. SUBTRACT 1 FROM LARGESTNUM
  82. SUBTRACT 1 FROM THIRDCOUNTER.
  83.  
  84.  
  85. LargestNumFactorial.
  86. PERFORM GetLargestNum UNTIL THIRDCOUNTER > 5
  87. DISPLAY LARGESTNUM
  88. MOVE LARGESTNUM TO THIRDCOUNTER
  89. PERFORM FactorialProcess UNTIL THIRDCOUNTER = 0.
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Success #stdin #stdout 0.01s 5276KB
stdin
1
1
2
3
4
5
2
3
0
4
stdout
 MENU 
[1] Fill array 
[2] Print Array 
[3] Factorial of Largest Number 
[4] Exit 
 Choice :  Enter positive integer:  Enter positive integer:  Enter positive integer:  Enter positive integer:  Enter positive integer:  MENU 
[1] Fill array 
[2] Print Array 
[3] Factorial of Largest Number 
[4] Exit 
 Choice : 1 2 3 4 5  
 MENU 
[1] Fill array 
[2] Print Array 
[3] Factorial of Largest Number 
[4] Exit 
 Choice : 5
000120
 MENU 
[1] Fill array 
[2] Print Array 
[3] Factorial of Largest Number 
[4] Exit 
 Choice :  INVALID CHOICE 
 MENU 
[1] Fill array 
[2] Print Array 
[3] Factorial of Largest Number 
[4] Exit 
 Choice :  Goodbye