Site icon T4Tutorials.com

C++ Program using Virtual Base Class to find HCF (Highest Common Factor) of two numbers

Write a C++ program to find HCF (Highest Common Factor) of two numbers using the Virtual base Class in Object Oriented Programming(OOP).

Highest Common Factor HCF C++

#include<iostream>
using namespace std;
class A
{
	public:int i;
};
class B:virtual public A
{
	public:int j;
};
class C: virtual public A
{
     public:int n1,n2;
};
class D:public B,public C
{
      public:int hcf;
 
         int Input()
        {
            hcf=1;
			cout<<"Enter no's:";
			cin>>n1>>n2;
			j=(n1<n2)?n1:n2;
				for(i=1;i<=j;i++)
				{
           if(n1%i==0 && n2%i==0)
               {
                 hcf= i;
               }
               }
         }
               int T4Tutorials_Show()
                {
					cout<<" Hcf is"<<hcf;
                }
				
       };
              
int main()
{
	D object;
    object.Input();
    object.T4Tutorials_Show();
	return 0;
}

Output

 

Some FAQ

C++ program  to find lcm of n numbers by using the Virtual base Class in Object Oriented Programming(OOP).

hcf of two numbers in c using the Virtual base Class in Object Oriented Programming(OOP).

write a C++ program  to find lcm of two numbers using the Virtual base Class in Object Oriented Programming(OOP).

write a program in c to find lcm of any two numbers using hcf using the Virtual base Class in Object Oriented Programming(OOP).

print the number of common factors of a and b in c using the Virtual base Class in Object Oriented Programming(OOP).

gcd of three numbers in c using the Virtual base Class in Object Oriented Programming(OOP).

C++ program  to find gcd of n numbers

Exit mobile version