当前位置:网站首页>2020-12-22最大公因数
2020-12-22最大公因数
2022-07-26 22:38:00 【沉梦昂志浮生若梦】
辗转相除求两个数的最大公因数
注意的要点
scanf("%d%d", &m, &n);中的&取地址符 因为scanf读取的数值要存入变量对应的内存地址中 &为取地址符 &&为与运算
该代码运行要注意交换m与n要使m大于n 这样否则n小于m的话取余不就直接是零了么
有了最大公约数就可以求出最小公倍数。在以后学了函数时,写一个函数返回最大的公约数同时使main中的 m与n不变 这样就可以让M*N/最大公因数这样就可以得到最小公倍数。
#include <stdio.h>
int main ()
{
int m, n, r;
scanf("%d%d", &m, &n);
if (m < n)
r = m, m = n, n = r;
while (r = m % n)
{
r = m % n;
m = n, n = r;
}
printf("最大的公约数为%d", n);
}
边栏推荐
- Chapter 7 course summary
- Anaconda = > pycharm=> CUDA=> cudnn=> pytorch environment configuration
- 转置卷积相关
- Codeforces D. two divisors (number theory, linear sieve)
- Arcgis和Cass实现断面展高程点
- Midge paper reading notes
- Pyautogui usage example
- 哨兵2号(Sentinel-2)的下载及处理
- Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise
- 4. Talk about the famous Zhang Zhengyou calibration method
猜你喜欢

01 knapsack problem 416. Segmentation and equal sum subset -494. Goal and

Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise

8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)

Signal and system impulse response and step response

哨兵2号(Sentinel-2)的下载及处理

2022_ SummerBlog_ 008

Sliding window problem summary

Relationship between limit, continuity, partial derivative and total differential of multivariate function (learning notes)

The crawler parses the object of the web page. Element name method

裁剪tif影像
随机推荐
10_ Evaluate classification
V-viewer use
Codeforces E. maximum subsequence value (greed + pigeon nest principle)
12_ Decision tree
deeplabcut使用1
Friend友元函数以及单例模式
查看 Anaconda 创建环境的位置
Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise
卷积神经网络——LeNet(pytorch实现)
傅里叶分析(基础介绍)
RESNET paper interpretation and code implementation (pytorch)
Flink SQL (II) Kafka connector
简单的素数程序 初学者 希望码龄高的大佬可以一下
Leetcode - hash table
知识蒸馏——pytorch实现
CSDN article syntax rules
蒙着头配置deeplabcut2
Search engine hijacking of black hat SEO
10_评价分类结果(Evaluate classification)
Sliding window problem summary