精華區beta NTUBIME101HW 關於我們 聯絡資訊
#include <iostream> using namespace std; void function(int,int); int main() { int a,b; cout << "Please input a b,input 0 0 exit.\n"; while(1) { cin >> a >> b; if(a==0 && b==0) break; function(a,b); } return 0; } void function(int M,int m) { int temp,a=M,b=m; while(b!=0) { temp = b; b = (a%b); a = temp; }//輾轉相除法 cout << "GCD: " << a << endl; cout << "LCM: " << M*m/a << endl; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.232.97.219
vincent79715:神人果然是神人 12/08 02:19
sb0917:... 12/08 02:23