Created
September 23, 2021 23:28
-
-
Save Red0214/d9d966d184d9f85c86ffb5a7a0c3f5b5 to your computer and use it in GitHub Desktop.
Error resuelto de un ejercicio de Programación ATS en el curso de C++
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
| // Crear un programa que determine si una matriz es simetrica o si no lo es. | |
| // Invocamos las librerias, creamos variables y les asignamos valores. | |
| #include <iostream> | |
| #include <conio.h> | |
| using namespace std; | |
| int rows, columns; // Utiles para una matriz. | |
| int count; // Util para un conteo. | |
| char answer = 'F'; | |
| // Se ejecuta la funcion principal. | |
| int main(){ | |
| // Se ingresan valores y se configuran las dimensiones de la matriz. | |
| cout<<"--- DETERMINAR SI UNA MATRIZ ES SIMETRICA ---"; | |
| cout<<endl<<endl; | |
| cout<<"Ingrese el numero de filas: "; | |
| cin>>rows; | |
| cout<<"Ingrese el numero de columnas: "; | |
| cin>>columns; | |
| cout<<endl; | |
| int matrix[rows][columns]; | |
| // Si el numero de filas y de columnas es el mismo, se pasa al siguiente paso. | |
| if(rows == columns){ | |
| // Se ingresa a un ciclo for para almancenar valores en la matriz. | |
| for(int i = 0; i < rows; i++){ | |
| for(int j = 0; j < columns; j++){ | |
| // Se ingresan valores. | |
| cout<<"Ingrese un valor para la posicion ["<<i<<"]["<<j<<"]: "; | |
| cin>>matrix[i][j]; | |
| } | |
| } | |
| // Verifica si la matriz original tiene el mismo orden que la matriz transpuesta. | |
| for(int i = 0; i < rows; i++){ | |
| for(int j = 0; j < columns; j++){ | |
| if(matrix[i][j] != matrix[j][i]){ | |
| // Si los valores no son iguales, el contador aumenta. | |
| count = count + 1; | |
| } | |
| else{ | |
| // Si los valores son iguales, el contador no cambia. | |
| count = count; | |
| } | |
| } | |
| } | |
| } | |
| else{ | |
| count = 1; | |
| } | |
| // Si el contador es igual a cero, la matriz es simetrica. | |
| if(count == 0){ | |
| // Se muestran las matrices ingresadas. | |
| cout<<endl; | |
| cout<<"--- MOSTRANDO MATRICES ---"; | |
| cout<<endl<<endl; | |
| cout<<" MATRIZ ORIGINAL"<<" MATRIZ TRANSPUESTA"; | |
| cout<<endl<<endl; | |
| // Se ingresa a un ciclo for para mostrar las matrices. | |
| for(int i = 0; i < rows; i++){ | |
| cout<<" | "; | |
| for(int j = 0; j < columns; j++){ | |
| // Se muestra la matriz original. | |
| cout<<matrix[i][j]<<" | "; | |
| } | |
| cout<<"\t"; | |
| cout<<" | "; | |
| for(int k = 0; k < rows; k++){ | |
| // Se muestra la matriz transpuesta. | |
| cout<<matrix[k][i]<<" | "; | |
| } | |
| cout<<endl; | |
| } | |
| cout<<endl; | |
| cout<<"La matriz es simetrica."; | |
| } | |
| /* Si el numero de columnas y filas es diferente, o si el contador es diferente de cero. | |
| la matriz no es simetrica. */ | |
| else if(count != 0 || rows != columns || columns != rows){ | |
| cout<<"--- ERROR MOSTRANDO MATRICES ---"; | |
| cout<<endl<<endl; | |
| cout<<"La matriz no es simetrica."; | |
| } | |
| getch(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment