Write a C++ program to find Strong Numbers within a range of numbers using class and Objects 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 | #include<iostream> using namespace std; class T4Tutorials { protected : int i, n, T4Tutorials_number, T4Tutorials_Strong , j, k, T4Tutorials_Ending, T4Tutorials_Starting; public : int find() { T4Tutorials_Strong = 0; long fact; cout << "Find Strong Numbers within a range of numbers:"<<endl; cout << "----------"<<endl; cout << "Input starting range of number: "<<endl; cin >> T4Tutorials_Starting; cout << "Input Ending range of number: "<<endl; cin >> T4Tutorials_Ending; cout << "The Strong numbers are: "<<endl; for (k = T4Tutorials_Starting; k <= T4Tutorials_Ending; k++) { T4Tutorials_number = k; T4Tutorials_Strong = 0; for (j = k; j > 0; j = j / 10) { fact = 1; for (i = 1; i <= j % 10; i++) { fact = fact * i; } T4Tutorials_Strong = T4Tutorials_Strong + fact; } if (T4Tutorials_Strong == T4Tutorials_number) cout << T4Tutorials_number << " "<<endl; } cout << T4Tutorials_Ending<<endl; } }; int main() { T4Tutorials 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