返回列表 發帖
#include<iostream>      

using namespace std;     

int main()      

{     
   int a,b,c,maxf;
    cout<<"請輸入第一個數:"<<endl;
    cin>>a;
    cout<<"請輸入第二個數:"<<endl;
    cin>>b;
    c=(a<b)?a:b;  
    cout<<a<<","<<b<<"的最大公因數有:";
    for( int i=1;i<=c;i++ )
    {
       if(a%i==0 && b%i==0)   
       {
           maxf=i;
           
              
       }   
    }
     cout<<maxf;
   
   
   
   
   
              

    system("pause");

    return 0;   

}

TOP

返回列表