-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddition.php
More file actions
151 lines (141 loc) · 7 KB
/
addition.php
File metadata and controls
151 lines (141 loc) · 7 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<div class="wrapper style2">
<section class="container">
<div class="col-md-12">
<form name="form1" action="" method="post" >
<div class="col-md-6">
<label>Enter the number of rows for matrix :</label>
</div>
<div class="col-md-6">
<input type="text" name="row" id="row" value="<?php echo isset($_POST['row']) ? $_POST['row'] : '' ;?>">
</div>
<div class="col-md-6">
<label>Enter the number of columns for matrix :</label>
</div>
<div class="col-md-6">
<input type="text" name="col" id="col" value="<?php echo isset($_POST['col']) ? $_POST['col'] : '' ;?>">
</div>
<div class="col-md-6">
<input type="button" name="create" value="Create Matrix" onclick="createMatrix()">
</div>
<div class="col-md-12">
<div id="matrixA">
</div>
</div>
<div class="col-md-12">
<div id="matrixB">
</div>
</div>
<div class="col-md-12">
<div id="matrixC">
</div>
</div>
<div class="col-md-12">
<input type="submit" name="submit" value="submit" class="submit" onclick="addMatrix()">
</div>
<div class="col-md-12">
<div class="create">
<script>
function createMatrix() {
var row = document.getElementById('row').value;
var col = document.getElementById('col').value;
var i , j , m , n;
if (row == '') {
alert('Please Enter Number Of Rows!');
return false;
}
if (col == '') {
alert('Please Enter Number Of Columns !');
return false;
}
var amatrix = new Array();
var htmlA = 'Enter the A matrix :';
htmlA += '<table>';
for (i = 0; i < row; i++) {
amatrix[i] = new Array();
htmlA += '<tr>';
for (j = 0; j < col; j++) {
htmlA += '<td>';
htmlA += '<input type="text" name="amatrix[' + i + '][' + j + ']">';
htmlA += '</td>';
}
htmlA += '</tr>';
}
htmlA += '</table>';
document.getElementById('matrixA').innerHTML = htmlA;
var bmatrix = new Array();
var htmlB = 'Enter the B matrix :';
htmlB += '<table>';
for (i = 0; i < row; i++) {
bmatrix[i] = new Array();
htmlB += '<tr>';
for (j = 0; j < col; j++) {
htmlB += '<td>';
htmlB += '<input type="text" name="bmatrix[' + i + '][' + j + ']">';
htmlB += '</td>';
}
htmlB += '</tr>';
}
htmlB += '</table>';
document.getElementById('matrixB').innerHTML = htmlB;
}
function checkMatrix() {
var row = document.getElementById('row').value;
var col = document.getElementById('col').value;
if (row == '' || col == '') {
alert('Please Create Matrix First!');
return false;
}
else {
return true;
}
}
function addMatrix(){
var cmatrix = new Array();
var row = document.getElementById('row').value;
var col = document.getElementById('col').value;
var m , n;
var htmlC = 'Addition of matrix :';
htmlC += '<div class="box col-md-6" >';
for (m = 0; m < row; m++) {
cmatrix[i] = new Array();
for (n = 0; n < col; n++) {
cmatrix[m][n] = amatrix[m][n] + bmatrix[m][n];
}
}
}
htmlC += '</div>';
document.getElementById('matrixC').innerHTML = htmlC;
</script>
</div>
</div>
</form>
</div>
<!-- <?php
if (@$_POST['submit'] === 'submit') {
$amatrix = $_POST['amatrix'];
$bmatrix = $_POST['bmatrix'];
$row = $_POST['row'];
$col=$_POST['col'];
if (!is_array($amatrix) && !is_array($bmatrix)) {
echo "Please Create Matrix First by Clicking on Create Matrix!";
exit;
}
echo '<div class="col-md-4">';
echo '<div class="row">';
echo '<p>The resultant matrix is :</p>';
for ($m = 0; $m < $row; $m++) {
echo '<div class="box col-md-6" >';
for ($n = 0; $n < $col; $n++) {
$cmatrix[$m][$n] = $amatrix[$m][$n] + $bmatrix[$m][$n];
echo '<h2>';
print_r($cmatrix[$m][$n]);
echo '</h2>';
}
echo '</div>';
}
echo '</div>';
echo '</div>';
}
?> -->
</section>
</div>