用c语言编写求两个数的最小公倍
时间: 2023-02-27 16:07:22 浏览: 48
数的代码如下:
```
#include <stdio.h>
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
int a, b;
printf("请输入两个整数:");
scanf("%d%d", &a, &b);
int g = gcd(a, b);
printf("它们的最小公倍数是:%d\n", a * b / g);
return 0;
}
```
相关问题
如何用C语言编写求两个数的最小公倍数的函数?
以下是用C语言编写求两个数的最小公倍数的函数的示例代码:
```c
#include <stdio.h>
int gcd(int m, int n) {
int r;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int lcm(int m, int n) {
return m * n / gcd(m, n);
}
int main() {
int m, n;
printf("请输入两个正整数:\n");
scanf("%d %d", &m, &n);
printf("%d和%d的最小公倍数是:%d\n", m, n, lcm(m, n));
return 0;
}
```
C语言编写求两个数中的最大值
我们可以使用以下C语言程序来求出两个数字中的最大值:int max(int num1, int num2)
{
/* 声明变量 */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)