forked from SarahN18/Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrong_num.cpp
More file actions
37 lines (32 loc) · 727 Bytes
/
strong_num.cpp
File metadata and controls
37 lines (32 loc) · 727 Bytes
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
//if summation of factorial of each digit returns the original number then it is a strong number
#include<iostream>
using namespace std;
int factorial(int n){
if(n==0 || n==1) {
return 1;
}
else
return n * factorial(n-1);
}
int strongNumber(int n){
int strong=0;
int original=n;
while(n!=0){
int temp = n % 10;
strong += factorial(temp);
n/=10;
}
if(strong==original) {
cout<<original<<" is a Strong number"<<endl;
}
}
int main(){
int x,y; //x=lower limit,y=upper limit
cout << "Enter the range: ";
cin>>x>>y;
//strong numbers within a range
for(int i=x; i<=y; i++){
strongNumber(i);
}
return 0;
}