返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int number,number2,x=1,cont=0;
  7.     cout<<"請輸入一個數字並按enter:";
  8.    
  9. cin>>number;
  10.     cout<<"請輸入另一個數字並按enter:";
  11.     cin>>number2;
  12.     cout<<number<<"和"<<number2<<"的公因數有:";
  13.     while(x<=number && x<=number2)
  14.     {
  15.         if(number%x == 0 && number2%x == 0)
  16.         {
  17.             cout<<x<<" ";        
  18.             cont+=1;
  19.         }
  20.         x+=1;
  21.     }
  22.     cout<<endl;
  23.     cout<<"共"<<cont<<"個"<<endl;
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表