forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.js
More file actions
42 lines (35 loc) · 974 Bytes
/
Armstrong.js
File metadata and controls
42 lines (35 loc) · 974 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
38
39
40
41
42
// In this programe we will check whether a number is angstrom or not
// An Armstrong number of a three-digit number is a number in which
// the sum of the cube of the digits is equal to the number itself.
// Hence 153 is an Armstrong number
process.stdin.setEncoding("utf-8");
var str = "";
process.stdin.on("data", (data) => {
str += data;
});
process.stdin.on("end", () => {
str = str.split("\n");
var number = str[0];
var temp = number;
var answer = 0;
var rem = 0;
var n = 0;
while (temp != 0) {
temp = Math.floor(temp / 10);
n++;
}
temp = number;
while (temp != 0) {
rem = Math.floor(temp % 10);
answer = answer + Math.pow(rem, n);
temp = Math.floor(temp / 10);
}
if (answer == number)
console.log(number + " is an Armstrong number.");
else
console.log(number + " is not an Armstrong number.");
});
// Example
// Input 321
// Output:- 371 is an Armstrong number.
// Explanation 3*3*3+7*7*7+1*1*1 = 371