当前位置:网站首页>【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
2022-07-31 02:45:00 【rookieﻬ°】
废话不多说,直接上代码:
int main()
{
int m, n;
scanf("%d%d", &m, &n);
int mul = m * n;
int mod = m % n;
if (m == n)//解决当m==n的情况,如果m==n,那么mod==0,将造成程序浮点型错误
printf("%d\n", 2 * m);
else
{
do//辗转相除法
{
m = n;
n = mod;
mod = m % n;
} while (mod);
printf("%d\n", mul / n + n);
}
return 0;
}
【解释在标注上】
有问题请留言。
边栏推荐
猜你喜欢

How to design the changing system requirements

汉源高科8路HDMI综合多业务高清视频光端机8路HDMI视频+8路双向音频+8路485数据+8路E1+32路电话+4路千兆物理隔离网络

CorelDRAW2022精简亚太新增功能详细介绍

SQL注入 Less46(order by后的注入+rand()布尔盲注)

Teach you how to configure Jenkins automated email notifications

加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还

Real-time image acquisition based on FPGA

图像处理技术的心酸史

Drools Rule Properties, Advanced Syntax

The whole process scheduling, MySQL and Sqoop
随机推荐
Why is String immutable?
Drools basic introduction, introductory case, basic syntax
Introduction to flask series 】 【 flask - using SQLAlchemy
4. Sensitive word filtering (prefix tree)
数学解决——环形链表问题
【C语言基础】解决C语言error: expected ‘;‘, ‘,‘ or ‘)‘ before ‘&‘ token
Validate XML documents
Linux下redis7的安装,启动与停止
What level of software testing does it take to get a 9K job?
Pythagorean tuple od js
编译Hudi
6、显示评论和回复
[1153] The boundary range of between in mysql
Maximum area of solar panel od js
医疗影像领域AI软件开发流程
The real CTO is a technical person who understands products
The Sad History of Image Processing Technology
15. Website Statistics
print task sorting js od huawei
Android's webview cache related knowledge collection