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