-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas3.js
More file actions
74 lines (63 loc) · 1.52 KB
/
as3.js
File metadata and controls
74 lines (63 loc) · 1.52 KB
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
65
66
67
68
69
70
71
72
73
74
// Using for loops, write a Javascript program to output the following
// pattern -
// 1
// 2 3
// 4 5 6
// 7 8 9 10
var count= 1
for(i=1;i<=10;i++){
for(j=1;j<=i;j++){
process.stdout.write(count)
}
count = count+1
console.log()
}
// 2. Write a program to find whether a given number is armstrong number or
// not-
// The Armstrong number is a number that is equal to the sum of cubes of
// its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong
// numbers. Let's try to understand why 153 is an Armstrong number.
// 153 = (1*1*1)+(5*5*5)+(3*3*3) where:
// (1*1*1)=1
// (5*5*5)=125
// (3*3*3)=27
// So:
// 1+125+27=153
var no = 370
var sum = 1
arm = 0
for(let ele of no.toString()){
for(let i = 1; i<= no.toString().length;i++){
sum = Number(ele)*sum
}
arm = arm+sum
sum = 1
}
if(arm === no){
console.log(`${no} is armstrong number`);
}
else{
console.log(`${no} is not armstrong number`);
}
// 3. Write a program to find whether a given number is special number or
// not-
// If the sum of the factorial of digits of a number (N) is equal to the
// number itself, the number (N) is called a special number.
// eg- 145 is a special number
// Logic- 1! + 4! + 5!= 1+24+120 i.e 14
num = 146
fact = 1
sum = 0
for(let elem of num.toString()){
for(let i =1;i<=Number(elem);i++){
fact = fact*i
}
sum = sum+fact
fact =1
}
if(sum === num){
console.log(`${num} is special number`);
}
else{
console.log(`${num} is not a special number`);
}