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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#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