返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int x,y,X,Y,i=2,mult=1;
  7.      cout<<"請輸入第一個正整數:";
  8.      cin>>x;
  9.      cout<<"請輸入第二個正整數:";
  10.      cin>>y;
  11.      X=x;
  12.      Y=y;
  13.      while(x>0&&y>0)
  14.      {
  15.         if((x%i)==0&&(y%i)==0)
  16.         {
  17.             x=x/i;
  18.             y=y/i;                       
  19.             mult=mult*i;
  20.         }else
  21.         {
  22.            if(i>x||i>y)
  23.            {      
  24.                 break;   
  25.            }
  26.            i++;   
  27.         }
  28.      }
  29.      cout<<X<<"和"<<Y<<"的最小公倍數是"<<mult*x*y<<endl;

  30.      system("pause");
  31.      return 0;
  32. }
複製代碼

TOP

返回列表