forked from preeti-14-7/JavaScript-Program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08problem.js
More file actions
31 lines (23 loc) · 760 Bytes
/
08problem.js
File metadata and controls
31 lines (23 loc) · 760 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
// program to find Armstrong number between intervals
// write function
function Armstrong(lowNumber, highNumber){
// looping through lowNumber to highNumber
for (let i = lowNumber; i <= highNumber; i++) {
// converting number to string
let numberOfDigits = i.toString().length;
let sum = 0;
// create a temporary variable
let temp = i;
/* loop through a number to find if
a number is an Armstrong number */
while (temp > 0) {
let remainder = temp % 10;
sum += remainder ** numberOfDigits;
// removing last digit from the number
temp = parseInt(temp / 10); // convert float into integer
}
if (sum == i) {
console.log(i);
}
}
}