Skip to content
doubtly

2 answers

Answer: The GCD of 225 and 45 is 45. An object-oriented program puts the numbers and the GCD function inside a class.

#include <iostream>
using namespace std;

class GCD
{
    int a, b;
public:
    void getData(int x, int y)
    {
        a = x;
        b = y;
    }
    int find()
    {
        int x = a, y = b, r;
        while (y != 0)
        {
            r = x % y;
            x = y;
            y = r;
        }
        return x;
    }
    void display()
    {
        cout << "GCD of " << a << " and " << b
             << " is " << find() << endl;
    }
};

int main()
{
    GCD g;
    g.getData(225, 45);
    g.display();
    return 0;
}

How it works: the class GCD holds the two numbers as private data. find() uses Euclid's method: replace (x, y) by (y, x % y) until y becomes 0; then x is the GCD.

For 225 and 45: 225 % 45 = 0, so (x, y) becomes (45, 0) and the GCD is 45.

Output: GCD of 225 and 45 is 45

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.