class two_dimensional
{
addmatrix()
{
var first:number[][] = [[10],[10]];
var second:number[][] = [[10],[10]];
var i, j,m,n;
var sum:number[][] = [[10],[10]];
document.write("<h2>Two Dimension Array</h2><hr>");
m = parseInt(prompt("Enter the number of Rows of Matrix"));
n = parseInt(prompt("Enter the number of Columns of Matrix"));
document.write("<b>1st Matrix Elements :</b>");
for(i = 0; i < m; ++i)
{
for(j = 0; j < n; ++j)
{
first[i][j]=parseInt(prompt("Enter the element of First Matrix -> Row " + (i) + " And Coloumn " + (j)));
}
}
document.write("<br><br> ");
for(i = 0; i < m; i++ )
{
for(j = 0; j < n; j++)
{
document.write(" "+first[i][j]);
}
document.write("<br> ");
}
document.write("<br>");
document.write("<b>2nd matrix Elements :</b>");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
second[i][j]=parseInt(prompt("Enter the element of Second Matrix -> Row " + (i) + " And Coloumn " + (j)));
}
}
document.write("<br><br> ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
document.write(" " + second[i][j]);
}
document.write("<br> ");
}
for(i = 0; i < m; i++ )
{
for (j = 0; j < n; j++)
{
sum[i][j] = first[i][j] + second[i][j];
}
}
document.write("<br>");
document.write("<b>Sum of Enter Matrices :</b>");
document.write("<br><br> ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
document.write(" " + sum[i][j]);
}
document.write("<br> ");
}
}
}
window.onload = () => {
var matrix = new two_dimensional();
matrix.addmatrix();
}; |