返回列表 發帖
  1. #include<cstdlib>
  2. using namespace std;
  3. int main()
  4. {   
  5.      int a,b,c,max;
  6.      cout<<"請輸入第一個數:"<<endl;
  7.      cin>>a;
  8.      cout<<"請輸入第二個數:"<<endl;
  9.      cin>>b;
  10.      max=(a>b)?a:b;
  11.      c=a*b;
  12.      for(int i=max;i<=c;i++)
  13.      {
  14.           if(i%a==0 && i%b==0)
  15.           {
  16.                cout<<"兩數的最小公倍數為"<<i<<endl;
  17.                break;         
  18.           }                     
  19.      }     
  20.     system("pause");   
  21.     return 0;   
  22. }
複製代碼

TOP

返回列表