返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. class Demo{
  5.       public:
  6.              int a, b;
  7.              Demo(int a, int b){
  8.                       this->a = a;
  9.                       this->b = b;         
  10.              }
  11.              int DoSomething(){
  12.                  int tmp;
  13.                  while(this->a%this->b!=0){
  14.                      tmp=this->a%this->b;
  15.                      this->a=this->b;
  16.                      this->b=tmp;
  17.                  }
  18.                  return this->b;
  19.              }              
  20.       
  21.       
  22. };
  23. int main(){
  24.     int x, y;
  25.     cout<<"請輸入兩數:";
  26.     cin>>x>>y;
  27.     Demo hi(x,y);
  28.     cout<<"最大公因數為:"<<hi.DoSomething()<<endl;
  29.     system("pause");
  30.     return 0;   
  31. }
複製代碼

TOP

返回列表