-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCM_of_three_nums.c
95 lines (88 loc) · 2.12 KB
/
LCM_of_three_nums.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
int main()
{
int n1, n2, n3, max;
printf("Enter three positive integers: ");
scanf("%d %d %d", &n1, &n2, &n3);
// maximum number between n1 and n2 is stored in max
if (n1>n2)
{
if (n1>n3)
{
max = n1;
}
else
{
max = n3;
}
}
else
{
if (n2>n3)
{
max = n2;
}
else
{
max = n3;
}
}
while (1)
{
if ((max % n1 == 0) && (max % n2 == 0) && (max % n3 == 0))
{
printf("The LCM of %d and %d and %d is %d.", n1, n2, n3, max);
break;
}
++max;
}
return 0;
}
// #include <stdio.h>
// int main()
// {
// int N = 45;
// int N2 = 75;
// int N3 = 60;
// int LCM=1;
// int i = 2;
// while (i<9)
// {
// if (N % i == 0 && N2 % i == 0 && N3 % i == 0)
// {
// LCM = LCM * i;
// N = N/i;
// N2 = N2/i;
// N3 = N3/i;
// printf("The i is %d\n",i);
// i=0;
// }
// else if (N % i == 0 && N2 % i == 0 && N3 % i != 0)
// {
// LCM = LCM * i;
// N = N/i;
// N2 = N2/i;
// printf("The i is %d\n",i);
// }
// else if (N % i == 0 && N2 % i != 0 && N3 % i == 0)
// {
// LCM = LCM * i;
// N = N/i;
// N3 = N3/i;
// printf("The i is %d\n",i);
// }
// else if (N % i != 0 && N2 % i == 0 && N3 % i == 0)
// {
// LCM = LCM * i;
// N2 = N2/i;
// N3 = N3/i;
// printf("The i is %d\n",i);
// }
// else
// {
// LCM = LCM*N*N2*N3;
// }
// }
// printf("The LCM is %d",LCM);
// return 0;
// }