返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.           int x,y,counter,sum,z;
  8.           cout<<"請輸入2個數: ";
  9.           cin>>x;
  10.           cin>>y;
  11.          
  12.          
  13.           if(x<y){
  14.                 counter=x;
  15.                 }                        
  16.                 else{
  17.                 counter=y;
  18.             
  19.                           }
  20.                     cout<<x<<"和"<<y<<"和"<<"公因數:";      
  21.                     for(int i=1; i<=counter; i++)
  22.     {      
  23.                     if(x%i==0 && y%i==0)      
  24.                     {  
  25.                      int gcd;
  26.                      gcd=i;            
  27.                      cout<<i<<" ";
  28.                      counter++;
  29.                      sum+sum+i;      
  30.                                 }
  31.                        }
  32.                        
  33.                        
  34.                        
  35.                        
  36.                        int i;
  37.                        cout<<"最大公因數是"<<i<<endl;
  38.                        
  39.                        
  40.     goto re;         
  41.                                  
  42.     system("pause");
  43.     return 0;   
  44. }
複製代碼

TOP

返回列表