MultiLevel Inheritance C++ program to find Strong Numbers within a range of numbers
Write a C++ program to find Strong Numbers within a range of numbers using MultiLevel in object-oriented programming.
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 |
#include<iostream> using namespace std; class T4Tutorials { protected : int en, sn; }; class second : public T4Tutorials { protected : int i, n; }; class third : public second { protected : int n1, s1 , j, k; 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() { third a; a.find(); } |
Output
Find Strong Numbers within a range of numbers:
Input the starting range of number: 1
Input Ending range of number: 145
The Strong numbers are:
1
2
145