- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int x,y,X,Y,i=2,mult=1;
- cout<<"請輸入第一個正整數:";
- cin>>x;
- cout<<"請輸入第二個正整數:";
- cin>>y;
- X=x;
- Y=y;
- while(x>0&&y>0)
- {
- if((x%i)==0&&(y%i)==0)
- {
- x=x/i;
- y=y/i;
- mult=mult*i;
- }else
- {
- if(i>x||i>y)
- {
- break;
- }
- i++;
- }
- }
- cout<<X<<"和"<<Y<<"的最小公倍數是"<<mult*x*y<<endl;
- system("pause");
- return 0;
- }
複製代碼 |