当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

继承,继承,继承

查看 Anaconda 创建环境的位置

CCPD data set processing (target detection and text recognition)

LeetCode题目——数组篇

3_Jupyter Notebook, numpy和matplotlib

Iptables prevent nmap scanning and binlog

Helicopter control system based on Simulink

Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering

RecBole使用1

Sliding window problem summary
随机推荐
Shang school software testing (1) software testing curriculum system, advantages, learning suggestions, understanding software, software testing and defects, software testing process, debugging and te
类与对象笔记一
Based on the theoretical principle and simulation results of MATLAB spherical decoding, compare 2norm spherical decoding, infinite norm spherical decoding, ML detection
yolov5在jetson nano上的部署 deepstream
Iptables prevent nmap scanning and binlog
TypeScript(tsconfig.json)
The crawler parses the object of the web page. Element name method
12_ Decision tree
Arcgis和Cass实现断面展高程点
Anaconda = > pycharm=> CUDA=> cudnn=> pytorch environment configuration
LeetCode题目——数组篇
01 knapsack problem 416. Segmentation and equal sum subset -494. Goal and
Torch. correlation function
Drawing warehouse-3 (functional image)
Codeforces B. Orac and Models (dp)
Request attribute in crawler
傅里叶分析(基础介绍)
5_线性回归(Linear Regression)
Codeforces E. maximum subsequence value (greed + pigeon nest principle)
Oracle data guard service, process and protection mode