Skip to content

Commit 0002ce9

Browse files
authored
Merge pull request ashutosh97#102 from AustinZuniga/master
Added Least Common Multiple Problem
2 parents bc8b86e + ded7660 commit 0002ce9

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Least_Common_Multiple/LCM.cbl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
IDENTIFICATION DIVISION.
2+
3+
PROGRAM-ID.LCM.
4+
5+
ENVIRONMENT DIVISION.
6+
7+
DATA DIVISION.
8+
9+
WORKING-STORAGE SECTION.
10+
11+
01 ARRAY.
12+
02 A PIC 9(5) OCCURS 10 TIMES.
13+
77 N PIC 9(2) VALUE 2.
14+
77 I PIC 9(2).
15+
77 J PIC 9(2).
16+
77 Q PIC 9(3).
17+
77 R PIC 9(3).
18+
77 K PIC 9(5).
19+
77 B PIC 9(3) VALUE 0.
20+
77 C PIC 9(3) VALUE 0.
21+
77 D PIC 9(3) VALUE 0.
22+
77 P PIC Z(5)9.
23+
01 num PIC 999 VALUE 0.
24+
01 num2 PIC 999 VALUE 0.
25+
01 chickens PIC 999 VALUE 0.
26+
01 dogs PIC 999 VALUE 0.
27+
01 total PIC 999 VALUE 0.
28+
01 result PIC 99 VALUE 0.
29+
01 result1 PIC 999 VALUE 0.
30+
01 result2 PIC 999 VALUE 0.
31+
01 count1 PIC 999 VALUE 0.
32+
33+
PROCEDURE DIVISION.
34+
35+
MAIN-PARA.
36+
DISPLAY "ENTER " N " NUMBERS".
37+
PERFORM X-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
38+
PERFORM Y-PARA VARYING I FROM B BY 1 UNTIL C = N.
39+
MOVE K TO P.
40+
DISPLAY "THE LCM IS " P.
41+
42+
DISPLAY "Enter Number of Head".
43+
ACCEPT num.
44+
DISPLAY "Enter number of legs".
45+
ACCEPT num2.
46+
PERFORM headleg-PARA.
47+
if count1 equals 2 DISPLAY "NONE"
48+
STOP RUN.
49+
50+
X-PARA.
51+
ACCEPT A(I).
52+
IF (B < A(I))
53+
MOVE A(I) TO B.
54+
55+
Y-PARA.
56+
MOVE 0 TO C.
57+
COMPUTE D = D + 1.
58+
PERFORM Z-PARA VARYING J FROM 1 BY 1 UNTIL J > N.
59+
60+
Z-PARA.
61+
COMPUTE K = B * D.
62+
DIVIDE K BY A(J) GIVING Q REMAINDER R.
63+
IF (R = 0)
64+
COMPUTE C = C + 1.
65+
66+
headleg-PARA.
67+
PERFORM VARYING chickens FROM 0 BY 1 UNTIL chickens >= num
68+
COMPUTE dogs = num - chickens
69+
COMPUTE result =2 * chickens
70+
COMPUTE result1 =4 * dogs
71+
COMPUTE result2 = result + result1
72+
IF result2 EQUALS num2
73+
DISPLAY "[", chickens,",",dogs,"]"
74+
SET count1 to 1
75+
ELSE IF count1 equals to 1 set count1 to 1
76+
else set count1 to 2
77+
END-IF
78+
END-PERFORM.

Least_Common_Multiple/Problem.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Problem:
2+
3+
The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly
4+
divisible by both n1 and n2 (without a remainder). For example: the LCM of 72 and 120 is 360.
5+
6+
write a program written in COBOL that will compute the LCM of 2 numbers

0 commit comments

Comments
 (0)