当前位置:网站首页>【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;
}
【解释在标注上】
有问题请留言。
边栏推荐
- Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
- Mathematical Ideas in AI
- 【银行系列第一期】中国人民银行
- Basic learning about Redis related content
- The use of font compression artifact font-spider
- 全流程调度——MySQL与Sqoop
- [1154] How to convert string to datetime
- Linux下redis7的安装,启动与停止
- 7. List of private messages
- 局域网电脑硬件信息收集工具
猜你喜欢

6. Display comments and replies

Static route analysis (the longest mask matching principle + active and standby routes)

图解lower_bound&upper_bound

Layer 2 broadcast storm (cause + judgment + solution)

The Sad History of Image Processing Technology

Coldfusion file read holes (CVE - 2010-2861)

Maximum area of solar panel od js

mmdetection训练一个模型相关命令

JS 函数 this上下文 运行时点语法 圆括号 数组 IIFE 定时器 延时器 self.备份上下文 call apply

关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
随机推荐
英特尔软硬优化,赋能东软加速智慧医疗时代到来
What level of software testing does it take to get a 9K job?
知识蒸馏7:知识蒸馏代码详解
CorelDRAW2022精简亚太新增功能详细介绍
19.支持向量机-优化目标和大间距直观理解
什么是分布式锁?实现分布式锁的三种方式
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
工程(五)——小目标检测tph-yolov5
Unity3D Button mouse hover enter and mouse hover exit button events
Mathematical Ideas in AI
General introduction to the Unity interface
图解lower_bound&upper_bound
Discussion on Service Commitment of Class Objects under Multithreading
execsnoop tool
Calculate S=a+aa+…+aa…a
6、显示评论和回复
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击
mysql index
公司官网建站笔记(六):域名进行公安备案并将备案号显示在网页底部
The application of AI in the whole process of medical imaging equipment