- #include<iostream>
- #include<cstdlib>
- using namespace std;
- class Demo{
- public:
- int a, b;
- Demo(int a, int b){
- this->a = a;
- this->b = b;
- }
- int DoSomething(){
- int tmp;
- while(this->a%this->b!=0){
- tmp=this->a%this->b;
- this->a=this->b;
- this->b=tmp;
- }
- return this->b;
- }
-
-
- };
- int main(){
- int x, y;
- cout<<"請輸入兩數:";
- cin>>x>>y;
- Demo hi(x,y);
- cout<<"最大公因數為:"<<hi.DoSomething()<<endl;
- system("pause");
- return 0;
- }
複製代碼 |