返回列表 發帖
本帖最後由 黃宥華 於 2019-11-1 20:18 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int pig,e=0,sum=0,f=0;
  7.     re:
  8.     cout<<"請輸入第一個整數";
  9.     cin>>pig;
  10.     cout<<"請輸入第二個整數";
  11.     cin>>e;
  12.     cout<<pig<<"和"<<e<<"公的因數有";
  13.     f=pig>e?e:pig;
  14.     for(int i=1;i<=f;i++)
  15.     {
  16.         if(pig%i==0 && e%i==0)
  17.         {   
  18.              cout<<i<<" ";
  19.              sum++;
  20.         }
  21.               
  22.     }
  23.     cout<<endl;
  24.     cout<<"有"<<sum<<"個因數"<<endl;

  25.     goto re;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼
hahahahahahahaha

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int pig,e=0,sum=0,f=0;
  7.     re:
  8.     cout<<"請輸入第一個整數";
  9.     cin>>pig;
  10.     cout<<"請輸入第二個整數";
  11.     cin>>e;

  12.     f=pig>e?e:pig;
  13.     for(int i=1;i<=f;i++)
  14.     {
  15.         if(pig%i==0 && e%i==0)
  16.         {   
  17.          
  18.              sum=i;
  19.         }
  20.         
  21.               
  22.     }
  23.     cout<<endl;
  24.     cout<<"最大公因數為"<<sum<<endl;
  25.     goto re;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼
hahahahahahahaha

TOP

返回列表