forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrongNumber.dart
52 lines (45 loc) · 896 Bytes
/
StrongNumber.dart
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
import 'dart:io';
// Function to check if number is Strong
bool checkStrong(int num) {
int sum = 0;
int num_copy = num;
while (num_copy > 0) {
int digit = num_copy % 10;
sum += fact(digit);
num_copy ~/= 10;
}
if (sum == num) {
return true;
}
return false;
}
// Function to calculate factorial of a number
int fact(int number){
int result = 1;
int count = 1;
while(count <= number){
result *= count;
count++;
}
return result;
}
// Main Function with driver code
void main() {
print("Enter a number :");
int num = int.parse(stdin.readLineSync()!);
// Call function to check if number is Strong
if (checkStrong(num)) {
print("$num is a Strong Number");
} else {
print("$num is not a Strong Number");
}
}
/**
Sample input/output:
Enter a number :
145
145 is a Strong Number
Enter a number :
234
234 is not a Strong Number
*/