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

TOP

返回列表