第一次用C++写,欢迎大家不吝赐教
- #include <iostream>
- using namespace std;
- class test
- {
- public:
- test();
- test(int x, int y);
- ~test();
- int **();
- private:
- int a, b, temp;
- };
- test::test()
- {
- a = 0;
- b = 0;
- temp = 0;
- }
- test::test(int x, int y)
- {
- a = x;
- b = y;
- }
- int test::**()
- {
- if (a < b)
- {
- temp = a;
- a = b;
- b = temp;
- }
- if (a == b)
- return a;
- else
- {
- temp = b;
- while (b != 0)
- {
- temp = a % b;
- a = b;
- b = temp;
- }
- }
- return a;
- }
- int main()
- {
- int a, b, x;
- cout << "Please Input A and B :" << endl;
- cin >> a >> b;
- class test m(a, b);
- x = m.**();
- cout << a << "和" << b << "的公约数为:" << x;
- return 0;
- }