forked from stankin/oop-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab2.html
59 lines (57 loc) · 1.07 KB
/
lab2.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
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
function zigzag(n) {
a = [
['A00','A01','A02','A03','A04'],
['A10','A11','A12','A13','A14'],
['A20','A21','A22','A23','A24'],
['A30','A31','A32','A33','A34'],
['A40','A41','A42','A43','A44']
];
s = 'Èñõîäíàÿ ìàòðèöà:<br>';
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
s = s + ' ' + a[i][j];
}
s = s + '<br>';
}
m = 2*n-1;
s = s + '<br>Çèãçàã ïî ' + m + ' äèàãîíàëåé:<br>';
d = -1;
for (l=0; l<m; l++) { // öèêë ïî äèàãîíàëÿì
if (l<n) {
x1 = 0;
x2 = l;
} else {
x1 = l - n + 1;
x2 = n - 1;
}
for (i=0; i<=x2-x1; i++) {
if (d>0) {
x = x1+i;
y = x2-i;
} else {
x = x2-i;
y = x1+i;
}
s = s + ' (' + x + ',' + y + ')=' + a[x][y];
}
d = -d;
s = s + '<br>';
}
return s;
}
$(document).ready(function(){
$("#p1").click(function(){
document.getElementById("d1").innerHTML = zigzag(5);
});
});
</script>
</head>
<body>
<p id="p1">Íóæíî ñþäà êëèêíóòü</p>
<div id="d1"></div>
</body>
</html>