Suma la diogonal principal de una matriz
/*
* Created on 06/18/2005
*
* Suma la diogonal principal de una matriz
*/
package estructura;
/**
* @author vns
*
*/
public class sumaDiagonal {
/**
*
*/
public sumaDiagonal() {
super();
}
public static void main(String[] args) {
int matriz[][]={ {3,4,5},{6,2,6},{4,7,9} };
System.out.println( calcularDiagonal(matriz) );
}
public static int calcularDiagonal(int[][] matriz)
{
int suma = 0;
for (int i=0; i < matriz.length; i++)
{
suma+=matriz[i][i];
}
return suma;
}
}
* Created on 06/18/2005
*
* Suma la diogonal principal de una matriz
*/
package estructura;
/**
* @author vns
*
*/
public class sumaDiagonal {
/**
*
*/
public sumaDiagonal() {
super();
}
public static void main(String[] args) {
int matriz[][]={ {3,4,5},{6,2,6},{4,7,9} };
System.out.println( calcularDiagonal(matriz) );
}
public static int calcularDiagonal(int[][] matriz)
{
int suma = 0;
for (int i=0; i < matriz.length; i++)
{
suma+=matriz[i][i];
}
return suma;
}
}
0 Comments:
Post a Comment
<< Home