Skip to content

Commit 43bd333

Browse files
Add files via upload
1 parent 378bf29 commit 43bd333

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Program to find LCM (Lowest Common Multiple) of two numbers using a function.
2+
3+
#include <stdio.h>
4+
5+
int findLCM(int num1, int num2) {// create function findLCM() with parameters num1 and num2
6+
7+
int lcm;// compute lcm of two values and return it
8+
9+
if (num1 >= num2) {
10+
lcm = num1;
11+
}
12+
else {
13+
lcm = num2;
14+
}
15+
16+
while (1) {
17+
lcm = lcm + 1;
18+
if (lcm % num1 == 0 && lcm % num2 == 0) {
19+
break;
20+
}
21+
}
22+
return lcm;
23+
}
24+
25+
int main() {
26+
27+
int x, y;// get input value for x and y
28+
scanf("%d %d", &x, &y);
29+
30+
int lcm = findLCM(x, y);// call findLCM() with arguments x and y
31+
32+
printf("%d", lcm);// print the returned value
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)