How to resolve the algorithm Calculating the value of e step by step in the COBOL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Calculating the value of e step by step in the COBOL programming language

Table of Contents

Problem Statement

Calculate the value of   e.

(e   is also known as   Euler's number   and   Napier's constant.)

See details: Calculating the value of e

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Calculating the value of e step by step in the COBOL programming language

Source code in the cobol programming language

       >>SOURCE FORMAT IS FIXED
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EULER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
           01 EPSILON USAGE COMPUTATIONAL-2 VALUE 1.0E-15.
           01 FACT USAGE BINARY-DOUBLE UNSIGNED VALUE 1.
           01 N USAGE BINARY-INT UNSIGNED.
           01 E USAGE COMPUTATIONAL-2 VALUE 2.0.
           01 E0 USAGE COMPUTATIONAL-2 value 0.0.
           01 RESULT-MESSAGE.
              03 FILLER PIC X(4) VALUE 'e = '.
              03 RESULT-VALUE PIC 9.9(18) USAGE DISPLAY.
       PROCEDURE DIVISION.
       MAIN SECTION.
           PERFORM
              VARYING N FROM 2 BY 1
              UNTIL FUNCTION ABS(E - E0) < EPSILON
              MOVE E TO E0
              COMPUTE FACT = FACT * N
              COMPUTE E = E + 1.0 / FACT
           END-PERFORM.
           MOVE E TO RESULT-VALUE.
           DISPLAY RESULT-MESSAGE.
           STOP RUN.


  

You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Currency step by step in the C# programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Sidef programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Five weekends step by step in the Perl programming language