-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.IterationStatements.html
130 lines (108 loc) · 2.72 KB
/
3.IterationStatements.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>HANDSON 3</h1>
<script>
// Q1 Find the number of digits ( how many digits in the given number)
const Find_Digits = (num) => {
count = 0;
while (num !== 0) {
num = parseInt(num / 10);
count++;
}
return count;
};
// Q2 Find the Fives.
const Find_Five = (n) => {
let count = 0;
while (n > 0) {
if (n % 10 == 5) {
count = count + 1;
n = n / 10;
n = parseInt(n);
}
}
return count;
};
//Q3 Find Sum of all even number upto n
const findSum = (n) => {
{
let i,
sum = 0;
for (i = 2; i <= n; i += 2) {
sum += i;
}
return sum;
}
};
//Q4 Find the sum of the digits of a given number.
const Number_Sum = (n) => {
let ans = 0;
while (n !== 0) {
let digit = n % 10;
ans += digit;
n = n / 10;
n = parseInt(n);
}
return ans;
};
//Q4 Print the Odds bw 2 and n but print 2 first.
console.log(2);
const Print_Odd = (n) => {
for (let i = 2; i < n; i++) {
if (i % 2 !== 0) {
console.log(i);
}
}
};
//Q5 Print the following pattern:
// *
// **
// ***
// ****
// *****
const Print_pattern = (n) => {
for (let i = 1; i <= n; i++) {
let st = " ";
for (let j = 1; j <= i; j++) {
st = st + "*";
}
console.log(st);
}
};
//Q6 Check whether a Number is a prime or not.
const Prime_Check = (n) => {
let i;
for (i=1;i<=n;i++) {
if (n % i === 0) {
break;
}
}
if (i == n) {
return "YES";
} else {
return "NO";
}
};
//Q7 Print Numbers upto n
const printNumbers = (n) => {
for (let i = 1; i <= n; i++) {
console.log(i);
}
};
//Q8 Print the Table of the given number
const Print_Table = (N) => {
for (let i = 1; i <= 10; i++) {
let res = i * N;
console.log(N + " * " + i + " = " + res);
}
};
</script>
</body>
</html>