JavaScript - matriz cuadrada de nxn

 
Vista:

matriz cuadrada de nxn

Publicado por Xepher (2 intervenciones) el 15/09/2013 00:44:43
Recientemente me he estado aventurando un poco con javascript y html y por ocio me provocó hacer un programa que permita ingresar elementos en una matriz cuadrada de nxn y a través de una lista desplegable o varios botones se realicen las siguientes actividades: hallar el determinante de la matriz, mayor y menor elemento de la matriz, suma de la diagonal principal y la suma de todos los elementos de la matriz.

esto es lo que llevo de código:

El js:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
	<head>
		<script src = "ej6.js"></script>
		<script>
				var obj = {
					init: function(){
							var m = new Matrix (2);
							m.showDlg();
							var b = document.createElement("input");
							b.type = "button";
							b.value = "print";
							document.body.appendChild(b);
							b.onclick = function (){
							m.print();
							}
					}
				}
		</script>
	</head>
<body onload = "obj.init()" >
</body>
</html>

Y el HTML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
	<head>
		<script src = "ej6.js"></script>
		<script>
				var obj = {
					init: function(){
							var m = new Matrix (2);
							m.showDlg();
							var b = document.createElement("input");
							b.type = "button";
							b.value = "print";
							document.body.appendChild(b);
							b.onclick = function (){
							m.print();
							}
					}
				}
		</script>
	</head>
<body onload = "obj.init()" >
</body>
</html>


Les agradecería mucho si me pueden ayudar. Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

matriz cuadrada de nxn

Publicado por xve (2100 intervenciones) el 15/09/2013 09:19:48
Hola Xepher, los dos códigos que nos has mostrado son iguales¿?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

matriz cuadrada de nxn

Publicado por Xepher (2 intervenciones) el 15/09/2013 15:00:10
Ah, lo siento. Este es el js U.U'

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
var Matrix= fucntion(dim)
{
  	var tn=new Object();
	var e= new Object();
	var dimension = dim;
	var fila =0;
	var col=0;
 	var m=  [[], []];
	this.showDlg=function()
	{
		tn=document.createElement("textnode");
		tn.innerHTML= "Introduzca el valor" + fila + "," + col+" ";
		e= document.createElement("input");
 
		var b = document.createElement("input");
		b.type="button";
		b.value="leer";
 
		document.body.appendChild(tn);
		document.body.appendChild(e);
		document.body.appendChild(b);
		b.onclick=function()
		{
			addValue();
		}
	}
	var addValue=function()
	{
		m[col][fila]=e.value;
		col++;
		if(col==dimension)
		{
			col=0;
			fila++;
			if(fila==dimension)
			{
				col=0;
				fila=0;
			}
		}
		e.value=" ";
		tn.innerHTML="Introduzca el valor"+fila+ col+" ";
	}
	this.print=function()
	{
		var resp =" ";
		for(var f=0;f<dimension;f++)
			for(var c=0;c<dimesion;c++)
				resp+= m[c][f]+"-";
			alert(resp);
	}
}

y este el HTML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<head>
	<script src="ejj5.js"></script>
	<script>
	var obj=
	{
		init:function()
		{
			var m= new Matrix(2);
			m.showDlg;
			var b=document.createElement("input");
			b.type="button";
			b.value="print"
			b.onclick=function()
			{
				m.print();
			}
		document.body.appendChild(b);
		}
	}
	</script>
	</head>
	<body onload = "obj.init()">
	</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar