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

TOP

返回列表