Write a C+ program to find Strong Numbers within a range of numbers by using the inline function in C++.

The inline function inline T4Tutorials_Strong_Numbers::function()
helps to increase the execution time of a program. The programmer can make a request to the compiler to make the inline function as inline T4Tutorials_Strong_Numbers::function()
. Making inline means that compiler can replace the function definitions of inline T4Tutorials_Strong_Numbers::function()
to the place where this function is called a.function();
.
The compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
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
|
#include<iostream> using namespace std; class T4Tutorials_Strong_Numbers { protected : int i, n, n1; int s1 , j, k; int en, sn; public : function(); }; inline T4Tutorials_Strong_Numbers::function() { s1 = 0; long T4Tutorials_factorial; cout<<"Please Input starting range of number : "<<endl; cin>>sn; cout<<"Please 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) { T4Tutorials_factorial = 1; for (i = 1; i <= j % 10; i++) { T4Tutorials_factorial = T4Tutorials_factorial * i; } s1 = s1 + T4Tutorials_factorial; } if (s1 == n1) { cout << n1 << " "; } } cout<<endl; } int main() { T4Tutorials_Strong_Numbers a; a.function(); } |
Output
Please Input starting range of number :
1
Please Input ending range of number :
999
The Strong numbers are:
1 2 145