programming-examples/js/Functions/Write a JavaScript function which returns the n rows by n columns identity matrix..js
2019-11-15 12:59:38 +01:00

23 lines
511 B
JavaScript

function matrix(n) {
var i;
var j;
for (i=0; i < n; i++)
{
for (j=0; j < n; j++)
{
if (i === j)
{
console.log(' 1 ');
}
else
{
console.log(' 0 ');}
}
console.log('----------');
}
}
matrix(4);