-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.html
More file actions
47 lines (36 loc) · 1.08 KB
/
9.html
File metadata and controls
47 lines (36 loc) · 1.08 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
<!DOCTYPE html>
<html>
<!--
JavaScript program to check whether a matrix is a diagonal matrix or not. In linear algebra,
a diagonal matrix is a matrix in which the entries outside the main diagonal are all zero (the diagonal
from the upper left to the lower right).
for Example =>
[1, 0, 0], [0, 2, 0], [0, 0, 3] ]) = true
[1, 0, 0], [0, 2, 3], [0, 0, 3] ]) = false
-->
<head>
Exciese No :9
</head>
<body>
<script>
function checkMatrix(){
let a = new Array(3);
for (let i = 0; i < 3; i++) {
a[i] = new Array(3);
for ( let j = 0; j < 3; j++) {
a[i][j] = +prompt(`Enter [${i}] [${j}]:`);
}
}
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if(a[i][j] != 0 && i != j ){
return false;
}
}
}
return true;
}
alert(checkMatrix());
</script>
</body>
</html>