-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.htm
More file actions
44 lines (40 loc) · 1.1 KB
/
9.htm
File metadata and controls
44 lines (40 loc) · 1.1 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
<!-- Write a 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). -->
<!DOCTYPE html>
<html>
<head> </head>
<body>
<script>
let array = new Array();
let i = 0;
let j = 0;
let flag = false;
let n = +prompt( "Enter the n for n*n matrix")
for ( i = 0; i< n*n; i++) {
array[i] = +prompt( "Enter n*n matrix elements row wise", 0 );
}
for(i = 0; i < n; i++) {
for(j = 0; j < n, j++;) {
if( i==j ) {
continue;
}
if ( array[j + i*n] == 0 ) {
flag = true;
break;
}
else {
flag = false;
}
}
if ( flag == false ) {
break;
}
}
if ( flag == true ) {
alert ( "Given matrix is diagonal matrix" ) ;
}
else {
alert ( "Given matrix is not diagonal matrix" ) ;
}
</script>
</body>
</html>