標題:
C++求最大公約數與最小公倍數的源程序
[打印本頁]
作者:
51hei社區(qū)
時間:
2016-1-10 23:32
標題:
C++求最大公約數與最小公倍數的源程序
#include<iostream>
using namespace std;
int fun(int x,int y);
int main()
{int x,y;
cout<<"請輸入要求要兩個數:"<<endl;
cin>>x>>y;
int d=fun(x,y);
cout<<"最大公約數為:";
cout<<d;
cout<<"最小倍數等于: ";
cout<<x*y/d;
return 0;
}
int fun(int x,int y)
{
int t;
t=x%y;
if(t==0) return y;
else fun(y,t);
}
復制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1