#include<iostream.h>
#include<conio.h>
class GCD
{
public:
int a,b,q,r,tempa,tempb;
void getdata();
void calculate();
};
void GCD :: getdata()
{
cout<<"\nEnter the value of A: ";
cin>>a;
tempa=a;
cout<<"\nEnter the value of B: ";
cin>>b;
tempb=b;
}
void GCD :: calculate()
{
while(tempb>0)
{
q=tempa/tempb;
r=tempa-(q*tempb);
cout<<q<<"\t"<<tempa<<"\t"<<tempb<<"\t"<<r<<"\n";
tempa=tempb;
tempb=r;
}
cout<<"GCD("<<a<<","<<b<<") is"<<tempa<<"\n";
}
void main()
{
clrscr();
GCD g;
g.getdata();
g.calculate();
getch();
}
Download the CPP file from here






0 comments:
Post a Comment