-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer.c
More file actions
58 lines (44 loc) · 757 Bytes
/
computer.c
File metadata and controls
58 lines (44 loc) · 757 Bytes
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
#include <stdio.h>
int gys(int x, int y) // 计算最大公约数函数
{
int min;
if (x < y)
min = x;
else
min = y;
int i = min;
for (i; i > 0; i--)
{
if (x % i == 0 && y % i == 0)
{
return i;
break;
}
}
}
int gbs(int x, int y) // 计算最小公倍数函数
{
int max;
if (x < y)
max = y;
else
max = x;
int i = max;
for (i; i < 1000; i++)
{
if (i % x == 0 && i % y == 0)
{
return i;
break;
}
}
}
int main() // 测试用main函数
{
int a, b, x, y;
scanf("%d%d", &a, &b);
x = gys(a, b);
y = gbs(a, b);
printf("最大公约数%d最小公倍数%d\n", x, y);
return 0;
}