当前位置:网站首页>【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;
}
【解释在标注上】
有问题请留言。
边栏推荐
- mysql view
- How to do a startup CTO?
- First acquaintance with C language -- array
- Real-time image acquisition based on FPGA
- 6、显示评论和回复
- Unity3D Button mouse hover enter and mouse hover exit button events
- 【shell基础】判断目录是否为空
- How to build a private yum source
- Discussion on Service Commitment of Class Objects under Multithreading
- AI在医疗影像设备全流程应用
猜你喜欢

Live Preview | KDD2022 Doctoral Dissertation Award Champion and Runner-up Dialogue

字体压缩神器font-spider的使用

The use of font compression artifact font-spider

基于opencv实现人脸检测

Installation, start and stop of redis7 under Linux

Introduction to flask series 】 【 flask - using SQLAlchemy

The effective square of the test (one question of the day 7/29)

你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?

4、敏感词过滤(前缀树)

f.grid_sample
随机推荐
Teach you how to configure Jenkins automated email notifications
Drools Rule Properties, Advanced Syntax
Software accumulation -- Screenshot software ScreenToGif
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
16. Registration Center-consul
19.支持向量机-优化目标和大间距直观理解
User interaction + formatted output
多线程下类对象的服务承诺探讨
【Bank Series Phase 1】People's Bank of China
Brute Force/Adjacency List Breadth First Directed Weighted Graph Undirected Weighted Graph
tcp框架需要解决的问题
Introduction and use of Drools WorkBench
基于opencv实现人脸检测
What level of software testing does it take to get a 9K job?
TCP/IP四层模型
1. Non-type template parameters 2. Specialization of templates 3. Explanation of inheritance
SQL注入 Less46(order by后的注入+rand()布尔盲注)
Pythagorean tuple od js
8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
全流程调度——MySQL与Sqoop