Last active
December 1, 2017 03:19
-
-
Save iksaku/a90e6f9f37aef382d6a93683753c591b to your computer and use it in GitHub Desktop.
Pequeño script para crear matrices e imprimir varios de sus valores.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int numeros[999][999]; | |
int filas, columnas; | |
int i, j; | |
int x; | |
// Definición de la Matriz | |
cout << "Porfavor especifique el numero de lineas deseadas: "; | |
cin >> filas; | |
cout << endl << "Porfavor especifique el numero de columnas deseadas: "; | |
cin >> columnas; | |
cout << endl; | |
// Valores de la Matriz | |
for (i = 0; i < filas; i++) { | |
for (j = 0; j < columnas; j++) { | |
cout << "Introduzca el valor de [" << i << "][" << j << "]: "; | |
cin >> numeros[i][j]; | |
cout << endl; | |
} | |
} | |
// Diagonal principal de la matriz | |
cout << "Diagonal Principal: "; | |
for (i = 0, j = 0; i < filas; i++, j++) { | |
cout << numeros[i][j]; | |
if (i + 1 < filas) { | |
cout << ", "; | |
} | |
} | |
cout << endl; | |
// Valores bajo la diagonal principal | |
cout << "Valores debajo de la diagonal principal: "; | |
for (i = 0, j = 0; i < filas; i++, j++) { | |
for (x = 0; x < j; x++) { | |
cout << numeros[i][x]; | |
if (i + 1 < filas || x + 1 < j) { | |
cout << ", "; | |
} | |
} | |
} | |
cout << endl; | |
// Diagonal Inversa | |
cout << "Diagonal Inversa: "; | |
for (i = 0, j = columnas - 1; i < filas; i++, j--) { | |
cout << numeros[i][j]; | |
if (i + 1 < filas) { | |
cout << ", "; | |
} | |
} | |
cout << endl; | |
// Valores bajo la diagonal inversq | |
cout << "Valores debajo de la diagonal inversa: "; | |
for (i = 0, j = columnas - 1; i < filas; i++, j--) { | |
for (x = j + 1; x < columnas; x++) { | |
cout << numeros[i][x]; | |
if (i + 1 < filas || x + 1 < columnas) { | |
cout << ", "; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment