- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a, b, c, d, bigger, minb;
- cout<<"請輸入第一個數: ";
- cin>>a;
- cout<<"請輸入第二個數: ";
- cin>>b;
- cout<<"請輸入第三個數: ";
- cin>>c;
- d=(a>b)?a:b;
- bigger=(c>d)?c:d;
- for(int i=bigger; i<=a*b*c; i++)
- {
- if(i%a==0 && i%b==0 && i%c==0)
- {
- minb=i;
- break;
- }
- }
- cout<<a<<","<<b<<","<<c<<"的最小公倍數是: "<<minb<<endl;
- system("pause");
- return 0;
- }
複製代碼 |