返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     int x,y,s,b=0;
  6.     cout<<"請輸入2個正整數:";
  7.     cin>>x>>y;
  8.     if(y>x){
  9.     s=x;}
  10.     else{
  11.     s=y;
  12.     for(int i=s;i>=1;i--){
  13.     if(x%i==0 && y%i==0){
  14.     b=i;
  15.     break;
  16.     }}
  17.     cout<<endl<<x<<"和"<<y<<"的最小公倍數是"<<x*y/b<<endl;
  18.     system("pause");
  19.     return 0;
  20.     }
複製代碼
Attention Seeker </3

TOP

返回列表