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

TOP

返回列表