Skip to content
View jrg94's full-sized avatar
πŸ’
Watching hockey
πŸ’
Watching hockey

Organizations

@TheRenegadeCoder

Block or report jrg94

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
jrg94/README.md

Welcome to My Profile!

This week's code snippet, Factorial in Cobol, is brought to you by Subete and the Sample Programs repo.

IDENTIFICATION DIVISION.
        PROGRAM-ID. FACTORIAL.
        DATA DIVISION.
        WORKING-STORAGE SECTION.
          01 CMD-ARGS                  PIC X(38).
          01 DECINUM                  PIC S9999v99.
          01 NUM                      PIC S9(7).
          01 FACTORIAL                PIC 9(15) VALUE 1.
          01 LEFT-JUST-NUMBER         PIC X(16).
          01 WS-TALLY1                PIC 99 VALUE 0.
          01 CNT                      PIC 9(7) VALUE 1.

        PROCEDURE DIVISION.
           ACCEPT CMD-ARGS FROM COMMAND-LINE.

           IF CMD-ARGS IS ALPHABETIC THEN
              PERFORM ERROR-PARA.
           
      * Convert CMDARGS to it's numeric value
           COMPUTE DECINUM = FUNCTION NUMVAL(CMD-ARGS).
           
           IF DECINUM < 0 THEN
              PERFORM ERROR-PARA.

      * Move the Decimal number to Non decimal number
           MOVE DECINUM TO NUM
      
      * If both are equal, then it was an integer
           IF NUM IS EQUAL TO DECINUM THEN
              IF NUM IS EQUAL TO 0 OR NUM IS EQUAL TO 1 THEN
                 DISPLAY 1
                 STOP RUN                 
              ELSE
                 PERFORM CALC-FACT UNTIL CNT > NUM
      
      * Process to left justify the number
                 INSPECT FACTORIAL TALLYING WS-TALLY1 FOR LEADING ZEROS
                 Move FACTORIAL (WS-TALLY1 + 1 :) TO LEFT-JUST-NUMBER
      * Display the left justified result
                 DISPLAY LEFT-JUST-NUMBER
                 STOP RUN
           ELSE 
              PERFORM ERROR-PARA.
           
           
          CALC-FACT.
            COMPUTE FACTORIAL = FACTORIAL * CNT
            COMPUTE CNT = CNT + 1.

          ERROR-PARA.
           DISPLAY "Usage: please input a non-negative integer".
           STOP RUN.

Below you'll find an up-to-date list of articles by me on The Renegade Coder. For ease of browsing, emojis let you know the article category (i.e., blog: βœ’οΈ, code: πŸ’», meta: πŸ’­, teach: 🍎)

Also, here are some fun links you can use to support my work.


This document was automatically rendered on 2025-05-02 using SnakeMD.

Pinned Loading

  1. TheRenegadeCoder/sample-programs TheRenegadeCoder/sample-programs Public

    Sample Programs in Every Programming Language

    BASIC 591 592

  2. TheRenegadeCoder/how-to-python-code TheRenegadeCoder/how-to-python-code Public

    A collection of Jupyter Notebooks from the How to Python series

    Jupyter Notebook 85 28

  3. TheRenegadeCoder/SnakeMD TheRenegadeCoder/SnakeMD Public

    A markdown generation library for Python.

    Python 43 11

  4. TheRenegadeCoder/image-titler TheRenegadeCoder/image-titler Public

    An image title generator using The Renegade Coder style

    Python 17 6

  5. JuxtaMIDI JuxtaMIDI Public

    Pinpointing Mistakes in MIDI Practice Recordings

    JavaScript 16 2

  6. Orpheus Orpheus Public archive

    An adventure game with a focus on 3D audio

    Python 3