Write a C++ program to find Strong Numbers within a range of numbers by using the virtual base class.
#include<iostream>
using namespace std;
class T4Tutorials_Grand_Class
{
public :
int i, n;
};
class parent_1:public virtual T4Tutorials_Grand_Class
{
public :
int n1, s1 ;
};
class parent_2:public virtual T4Tutorials_Grand_Class
{
public:
int j, k;
};
class derived:public parent_1 , public parent_2
{
protected :
int en, sn;
public :
int find()
{
s1 = 0;
long fact;
cout << "Find Strong Numbers within an range of numbers:”<<endl;
cout << "“<<endl;
cout << "Input starting range of number: “<<endl;
cin >> sn;
cout << "Input ending range of number: “<<endl;
cin >> en;
cout << "The Strong numbers are: “<<endl;
for (k = sn; k <= en; k++)
{
n1 = k;
s1 = 0;
for (j = k; j > 0; j = j / 10)
{
fact = 1;
for (i = 1; i <= j % 10; i++)
{
fact = fact * i;
}
s1 = s1 + fact;
}
if (s1 == n1)
cout << n1 << " “<<endl;
}
cout << endl;
}
};
int main()
{
derived a;
a.find();
}
Output
Find Strong Numbers within an range of numbers:
Input starting range of number: 1
Input ending range of number: 145
The Strong numbers are: 1 2 145
FAQ
C++ program to check strong number by using the virtual base class.
34 write a c++ program to check whether a number is strong number or not by using the virtual base class.
Powerful numbers in C++ by using the virtual base class.
write a C++ function to find all the strong numbers in a given list of numbers by using the virtual base class.
write a c program to input number from user and check whether number is strong number or not by using the virtual base class.
