Write a C++ program to find Strong Numbers within a range of numbers by using the virtual base class.
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 47 48 49 50 51 52 53 54 55 56 57 |
#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.