Note that there are some explanatory texts on larger screens.

plurals
  1. POaddition of matrix in php
    primarykey
    data
    text
    <p>I am trying to do matrix addition in php. Here i am trying to get the input from the user and make the array for addition. I tried this. i have some more mistakes here. any one can give the solution for this... Thanks in advance...</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form name="form1" action="matrixaddjs.php" method="post"&gt; Enter the number of rows for matrix : &lt;input type="text" name="ar"&gt; Enter the number of columns for matrix : &lt;input type="text" name="ac"&gt; &lt;input type="submit" name="submit" value="submit"&gt; &lt;script&gt; var row=document.getElementById('ar').value; var col=document.getElementById('ac').value; var i; var j; var k; var l; var amatrix= new array(); document.write('&lt;table&gt;'); for(i=0;i&lt;row;i++) { amatrix[i]=new array(j); document.write('Enter the A matrix :'); document.write('&lt;tr&gt;'); for(j=0;j&lt;col;j++) { document.write('&lt;td&gt;'); document.write('&lt;input type="text" name="amatrix[i][j]"&gt;'); document.write('&lt;/td&gt;'); } document.write('&lt;/tr&gt;'); } document.write('&lt;/table&gt;'); var bmatrix= new array(); document.write('Enter the B matrix :'); document.write('&lt;table&gt;'); for(i=0;i&lt;row;i++) { bmatrix[i]=new array(j); document.write('&lt;tr&gt;'); for(j=0;j&lt;col;j++) { document.write('&lt;td&gt;'); document.write('&lt;input type="text" name="bmatrix[i][j]"&gt;'); document.write('&lt;/td&gt;'); } document.write('&lt;/tr&gt;'); } document.write('&lt;/table&gt;'); &lt;/script&gt; &lt;/form&gt; &lt;?php if($_POST['submit']=== 'submit') { $amatrix=$_POST['amatrix']; $bmatrix=$_POST['bmatrix']; echo "&lt;table&gt;"; echo "The resultant matrix is :"; for($m=0;$m&lt;$ar;$m++) { echo "&lt;tr&gt;"; for($n=0;$n&lt;$ac;$n++) { $cmatrix[$m][$n]=$amatrix[$m][$n]+$bmatrix[$m][$n]; echo "&lt;td&gt;"; echo $cmatrix[$m][$n]; echo "&lt;/td&gt;"; } echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>if user gives:</p> <p>Enter the number of rows for matrix : 2</p> <p>Enter the number of columns for matrix : 2</p> <p>Enter the A matrix :</p> <p>2 4</p> <p>3 5</p> <p>Enter the B matrix :</p> <p>3 4</p> <p>5 6</p> <p>The resultant matrix is:</p> <p>5 8</p> <p>8 11</p> <p>This is my expected result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload