精華區beta NTUCH-HW 關於我們 聯絡資訊
功能 用到的觀念 CODE #include<iostream>//header file #include<iomanip> #include<cmath> using namespace std; using std::setw; using std::fixed; using std::setprecision; #include<string> using std::string; using std::getline; int hcf(int, int); int main() { int a ,b,t,ch; cout<<"enter 0 and exit "; while(1) { cout<<"enter two number"<<endl; cin>>a>>b; if(a==0||b==0) break; if(a<b) { t=a; a=b; b=t; } cout<<"HCF "<<hcf(a,b)<<endl; cout<<"lowest common multiple "<<a*b/hcf(a,b)<<endl; } system("pause"); return 0; } int hcf(int a, int b) { int temp; while(temp!=0) { temp=a%b; a=b; b=temp; } return a; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59