-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPROG8B.php
33 lines (33 loc) · 884 Bytes
/
PROG8B.php
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
<!DOCTYPE html>
<html>
<body>
<?php
function pr($a){
foreach ($a as $b) {
foreach ($b as $c) {
echo $c ." ";
}echo "<br>";
}echo "<br>";
}
$a = [[1,2,3],[4,5,6],[7,8,9]];
$b = [[7,8,9],[4,5,6],[1,2,3]];
echo "<b>First Matrix : </b><br>" ; pr($a);
echo "<b>Second Matrix : </b><br>"; pr($b);
for ($i=0; $i < 3; $i++)
for ($j=0; $j < 3; $j++)
$c[$i][$j] = $a[$j][$i];
echo "<b>Transpose Of First Matrix : </b><br>"; pr($c);
for ($i=0; $i < 3; $i++)
for ($j=0; $j < 3; $j++)
$c[$i][$j] = $a[$i][$j] + $b[$i][$j];
echo "<b>Addition Of Two Matrix : </b><br>"; pr($c);
for ($i=0; $i < 3; $i++)
for ($j=0; $j < 3; $j++){
$c[$i][$j] = 0;
for ($k=0; $k < 3; $k++)
$c[$i][$j] += $a[$i][$k] * $b[$k][$j];
}
echo "<b>Multiplication Of Two Matrix : </b><br>"; pr($c);
?>
</body>
</html>