-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCM_Euclid.c
65 lines (63 loc) · 1.21 KB
/
LCM_Euclid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
*File name:
*Source file name:
*Author: Tamkien Cao
*Last modified: Tue, Feb 26th, 2019
*Version: 2.0
*Changelog:
- Used function.
*Other info:
-This is the 20th exercise from the workshop.
-[README] The idea had been hacked from http://bit.do/eGvJu
**/
#include<stdio.h>
#include<stdlib.h>
int LCM(int a, int b)
{
int x;
while (1)//always true
{
x = a % b;
if (x == 0)
{
break;//see the reason in the link.
}
else
{
a = b;
b = x;
}
}
return b;
}
main()
{
int a, b;
printf("This program can find out the largest common multiplier (LCM) of two numbers.\n");
do
{
printf("Insert the greater number here, enter 0 to exit:\n");
scanf_s("%d", &a);
if (a == 0)
{
break;
}
else
{
printf("Insert the smaller number here:\n");
scanf_s("%d", &b);
if (b > a)
{
printf("Hey, enter the greater number first.\n");
}
else
{
printf("The LCM of your numbers is %d.\n", LCM(a, b));
}
}
} while (1);
printf("\n=================================\n");
printf("Written by Tamkien Cao. Thank you for using my application!\n");
//credit line, neu xoa dong nay ctrinh se ko chay duoc;
system("pause");
}