GCD of a number using class in C++ || OOP || Class || C++
In this, we are going to find GCD of a number using Class in C++ Programming Language.

The Code given below can be used in TURBO C++ Compilers: -


// GCD value
#include<iostream.h>
#include<conio.h>
class gcd
{
    int a, b;

public:
    void find();
};
void gcd ::find()
{
    cout<<"enter the value of a and b";
    cin >> a >> b;
    while (a != b)
    {
        if (a > b)
            a = a - b;
        if (b > a)
            b = b - a;
    }
    cout<<"the gcd :"<<a;
}
void main()
{
    gcd obj1;
    obj1.find();
    getch();
}

//.........Coded by ARADHANA MISHRA


    
  

The Code given below can be used in gcc/g++ Compilers: -


// GCD value
#include<iostream>
using namespace std;
class gcd
{
    int a, b;

public:
    void find();
};
void gcd ::find()
{
    cout<<"enter the value of a and b";
    cin>>a>>b;
    while (a != b)
    {
        if (a > b)
            a = a - b;
        if (b > a)
            b = b - a;
    }
    cout<<"the gcd :"<<a;
}
int main()
{
    gcd obj1;
    obj1.find();
    return 0;
}

//.........Coded by ARADHANA MISHRA
    
  
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post