当前位置:网站首页>【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;
}
【解释在标注上】
有问题请留言。
边栏推荐
- Introduction to flask series 】 【 flask - using SQLAlchemy
- StringJoiner详解
- Pythagorean tuple od js
- [1154] How to convert string to datetime
- Discourse Custom Header Links
- BAT can't sell "Medical Cloud": Hospitals flee, mountains stand, and there are rules
- 数学解决——环形链表问题
- 跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
- 基于opencv实现人脸检测
- There is a problem with the multiplayer-hlap package and the solution cannot be upgraded
猜你喜欢
Maximum area of solar panel od js
Introduction and use of Drools WorkBench
什么是分布式锁?实现分布式锁的三种方式
php 网站的多语言设置(IP地址区分国内国外)
Layer 2 broadcast storm (cause + judgment + solution)
6、显示评论和回复
Discourse Custom Header Links
SQL注入 Less54(限制次数的SQL注入+union注入)
How to design the changing system requirements
The principle of complete replication of virtual machines (cloud computing)
随机推荐
Live Preview | KDD2022 Doctoral Dissertation Award Champion and Runner-up Dialogue
【CV项目调试】CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT问题
Inter-vlan routing + static routing + NAT (PAT + static NAT) comprehensive experiment
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
Coldfusion file read holes (CVE - 2010-2861)
AtCoder Beginner Contest 261 部分题解
To write good test cases, you must first learn test design
Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?
软件积累 -- 截图软件ScreenToGif
[1154] How to convert string to datetime
Static routing + PAT + static NAT (explanation + experiment)
Hanyuan Hi-Tech 8-channel HDMI integrated multi-service high-definition video optical transceiver 8-channel HDMI video + 8-channel two-way audio + 8-channel 485 data + 8-channel E1 + 32-channel teleph
15. Website Statistics
What level of software testing does it take to get a 9K job?
php 网站的多语言设置(IP地址区分国内国外)
The principle of complete replication of virtual machines (cloud computing)
SQL注入 Less46(order by后的注入+rand()布尔盲注)
AI中的数学思想