看板 EE_DSnP 關於我們 聯絡資訊
剛剛沒看到要寫成遞回, 其實遞迴的程式比較不容易看懂, 除非必要, 否則還是用 while 就好... #include<iostream> using namespace std; int GCD(int a,int b) { if (b != 0) return GCD(b, a%b); return a; } int main() { int a,b,gcd; // 求出gcd=(a,b) cout<<"求最大公因數"<<endl; cout<<"請輸入兩個整數"<<endl; cin>>a>>b; gcd=GCD(a,b); cout<<"(a,b)="<<gcd<<endl; system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.131.190
lee7938:這個是作業嗎???好像沒有看到。還是只是課本上的習題? 10/10 20:39
ric2k1:這些要到 chap 4, 5, 6, 7, 8... 才會教 10/11 23:13