最大公约数与最小公倍数C++实现
2024-10-07 01:57:51
最大公约数为辗转相除法求得, 最小公倍数为两数之积与最大公约数的比值
#include<iostream>
using namespace std;
int gcd(int, int);
int mcm(int, int);
int main()
{
int a, b;
cout << "enter a and b: " << endl;
cin >> a >> b;
cout << "gcd : " << gcd(a, b) << endl;
cout << "mcm : " << mcm(a, b) << endl; system("pause");
return ;
}
int gcd(int a, int b)
{
while (a%b != )
{
int tmp = a;
a = b;
b = tmp % a;
}
return b;
}
int mcm(int a, int b)
{
return a * b / mcm(a, b);
}
最新文章
- CentOS6.7搭建LNMP环境
- Android调用WebService
- App Store2016年最新审核规则
- python logging bydate
- BZOJ4152The Captain[DIjkstra]
- 抽象类和抽象方法(关键字abstract)
- nodejs 5.2.0文档自翻译——HTTP模块
- android打包签名介绍
- eclipse最有用快捷键整理(转)
- R语言︱文本挖掘之中文分词包——Rwordseg包(原理、功能、详解)
- SQL Server 2008 下载及版本说明
- Python__装饰器练习题
- 三类设计模式UML图
- 1506.01186-Cyclical Learning Rates for Training Neural Networks
- Mac快捷键大全及cheatsheet插件
- Inception-v3的设计思路小结
- IDEA报错:Error starting ApplicationContext. To display the auto-configuration report re-run your application with &#39;debug&#39; enabled. (&#39;crmWatcherService&#39;错误)
- eclipse中Maven项目jar问题
- FFMPEG视音频编解码零基础学习方法 【荐】
- stl中的map经验