本帖最後由 鄭豊翰 於 2024-5-11 16:02 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int x, y, smaller, op;
- cout<<"請輸入第一個正整數: ";
- cin>>x;
- cout<<"請輸入第個正整數: ";
- cin>>y;
- smaller=x<y?x:y;
- cout<<x<<"與"<<y<<"的最大公因數是: ";
- for(int i=1; i<=x; i++)
- {
- if(x%i==0 && y%i==0)
- {
- op=i;
- }
- }
- cout<<op<<endl;
- goto re;
- return 0;
- }
複製代碼 |