-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path23Problem.js
64 lines (51 loc) · 1.15 KB
/
23Problem.js
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
53
54
55
56
57
58
59
60
61
62
63
64
// program to check an Armstrong number of three digits
let sum = 0;
const number = prompt('Enter a three-digit positive integer: ');
// create a temporary variable
let temp = number;
while (temp > 0) {
// finding the one's digit
let remainder = temp % 10;
sum += remainder * remainder * remainder;
// removing last digit from the number
temp = parseInt(temp / 10); // convert float into integer
}
// check the condition
if (sum == number) {
console.log(`${number} is an Armstrong number`);
}
else {
console.log(`${number} is not an Armstrong number.`);
}
<script>
// Javascript program to check if
// a number is Automorphic
// Function to check
// Automorphic number
function isAutomorphic(N)
{
// Store the square
if(N < 0) N = -N;
let sq = N * N;
// Start Comparing digits
while (N > 0)
{
// Return false, if any
// digit of N doesn't
// match with its square's
// digits from last
if (N % 10 != sq % 10)
return -1;
// Reduce N and square
N /= 10;
sq /= 10;
}
return 1;
}
// Driver code
let N = 5;
let geeks = isAutomorphic(N) ?
"Automorphic" :
"Not Automorphic";
document.write(geeks);
</script>