Learn COBOL programming language – Part 3: Some small programs with COBOL

Tram Ho

Previously we have learned the most basic data types and syntax to build a COBOL program, this time we try to read some complete programs.


1. Enter and display the information entered by the user on the screen

In the above program, you can enter 2 numbers, display on the screen, and sum, difference, product, quotient 2 numbers above.


2. Enter, display the date in the format:

In the above program, the current date is obtained by the symbols MM, DD, YY, then displayed in the format marked “-“.


3. Enter, display scores, average and rank:
For example:

The above program allows you to enter 3 columns of points, calculate the total score, average score and rank I, II, III of FAIL for 5 students.


4. Enter a number, check that the number is a prime number or not:

Above are some basic programs of COBOL, with very basic topics that we often encounter when learning new programming languages.
Here I would like to guide how to run an online COBOL program:

  • You go to https://www.tutorialspoint.com/compile_cobol_online.php to compile.
  • Paste your source code into the main.cobc tab, the parameters then paste into the STDIN tab.
  • Then execute and check the results.
    Hopefully through your 3 posts, you are more familiar with this old programming language. If you have any questions or need to discuss, you can post a comment to discuss. ?

Reference links:
https://surendersampath.wordpress.com/2017/11/13/cobol-sample-programs/

Share the news now

Source : Viblo