Displaying Source Code(s)
|
|
Harmonic Series
--------------------------------------------------------------------------------
Description : This program finds harmonic series for n:
1/1 + 1/2 + ... + 1/n upto accuracy of four decimal places.
IDENTIFICATION DIVISION.
PROGRAM-ID. HARMONIC.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC 9(4).
77 NA PIC Z(4).
77 IA PIC Z(4).
77 SUM PIC 9(3)9V9(4).
77 I PIC 9(4) VALUE 2.
77 SUMA PIC Z(3)9.Z(4).
77 X PIC 9(4)V9(4).
PROCEDURE DIVISION.
PARA-A.
DISPLAY ( 1 , 1 ) ERASE.
DISPLAY ( 2 , 1 ) "ENTER VALUE OF n:".
ACCEPT ( 2 , 16 ) N.
MOVE N TO NA.
DISPLAY ( 3 , 1 ) "HARMONIC SERIES FOR" NA " NUMBERS:".
DISPLAY " ".
MOVE 0 TO SUM.
DISPLAY " 1 / 1".
PARA-B.
IF I = N + 1
GO TO PARA-I.
MOVE I TO IA.
DISPLAY " + " "1 /" IA.
ADD 1 TO I.
GO TO PARA-B.
PARA-I.
MOVE 1 TO I.
PARA-C.
IF I = N + 1
GO TO PARA-D.
COMPUTE X = 1 / I.
COMPUTE SUM = X + SUM.
ADD 1 TO I.
GO TO PARA-C.
PARA-D.
MOVE SUM TO SUMA.
DISPLAY " =" SUMA.
STOP-PARA.
DISPLAY " ".
STOP RUN.
--------------------------------------------------------------------------------
|
|
|