第3週目項目3出力最大公約数最小公倍数
921 ワード
:
/*Copyright (c) 2016,
*All rights reserved.
* :
* :
* : 2016 3 12
* : v1.0
*
* :
* :
* :
*/
#include <iostream>
using namespace std;
int gcd(int n1,int n2);
int lcm(int n1,int n2);
int main(void)
{
int num1,num2;
int igcd,ilcm;
cout<<"please input two numbers : ";
cin>>num1>>num2;
igcd=gcd(num1,num2);
ilcm=lcm(num1,num2);
cout<<"the gcd is :"<<igcd<<endl;
cout<<"the lcm is :"<<ilcm<<endl;
return 0;
}
int gcd(int n1,int n2)
{
int r;
while(n2!=0)
{
r=n1%n2;
n1=n2;
n2=r;
}
return n1;
}
int lcm(int n1,int n2)
{
return n1*n2/gcd(n1,n2);
}
:
, ,
:
, C++, , 。