返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5. int x,y,tmp;
  6. re:
  7. cout<<"請依序輸入兩正整數";
  8. cin>>x>>y;
  9. cout<<x<<" "<<y<<"最大公因數";
  10. while(x%y!=0)
  11. {
  12. tmp=x%y;
  13. x=y;
  14. y=tmp;

  15. }
  16. cout<<y<<endl;
  17. cout<<endl;

  18. goto re;

  19. system("pause");
  20. return 0;

  21. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     re:
  7.     int a,b,tmp;
  8.     cout<<"請依序輸入兩個正整數: ";
  9.     cin>>a>>b;
  10.     cout<<a<<"與"<<b<<"的最大公因數為: ";
  11.     while(a%b!=0)
  12.     {
  13.         tmp=a%b;
  14.         a=b;
  15.         b=tmp;   
  16.     }
  17.     cout<<b<<endl<<endl;
  18.     goto re;
  19.     system("pause");
  20.     return 0;   
  21. }
複製代碼

TOP

返回列表