返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {

  6.     int a, b, c, d, sum=0,smaller;
  7.     cout<<"請輸入第一個數: ";
  8.     cin>>a;
  9.     cout<<"請輸入第二個數: ";
  10.     cin>>b;
  11.     cout<<"請輸入第三個數: ";
  12.     cin>>c;
  13.     smaller=(a<b)?a:b;
  14.     smaller=(b<c)?d:c;
  15.     for(int i=1; i<=smaller; i++)
  16.     {

  17.         if(a%i==0 && b%i==0 && c%i==0)
  18.            {
  19.            cout<<i<<" ";
  20.                    sum++;       
  21.            }
  22.     }
  23.        cout<<endl;
  24.            cout<<"總共有"<<sum<<"個因數"<<endl;   
  25.        system("pause");
  26.        return 0;
  27. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int a,b,c,d,smaller,sum=0;
  7. cout<<"***求三數的公因數***"<<endl;
  8. cout<<"請輸入第一個正整數: ";
  9. cin>>a;
  10. cout<<"請輸入第二個正整數: ";
  11. cin>>b;
  12. cout<<"請輸入第三個正整數: ";
  13. cin>>c;
  14. smaller=(a<b)?a:b;
  15. smaller=(c<d)?c:d;
  16.     for(int i=smaller;i>=1;i--)
  17.     {
  18.       if(a%i==0 && b%i==0 && c%i==0)   
  19.          cout<<i<<" ";
  20.          sum++;
  21.     }     
  22. cout<<"總共有"<<sum<<"個公因數";           
  23. cout<<endl;  
  24. system("pause");   
  25. return 0;   
  26. }
複製代碼

TOP

返回列表