aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2020-06-01 20:43:27 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2020-06-01 20:43:34 +0200
commit771882a2c87084613b64c4622caa53dfc2deede1 (patch)
treefe5ca5c73e42c40dd8691be65dfe7d08dd806c04
parenta92ba4a005e2bc0cb5b6f0f49cb8e6744e81fff5 (diff)
downloadAceptaElReto-771882a2c87084613b64c4622caa53dfc2deede1.tar.gz
AceptaElReto-771882a2c87084613b64c4622caa53dfc2deede1.zip
Resuelto 151 en c++: ¿Es matriz identidad?
-rw-r--r--c/151_esMatrizIdentidad.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/c/151_esMatrizIdentidad.cpp b/c/151_esMatrizIdentidad.cpp
new file mode 100644
index 0000000..ba6dd34
--- /dev/null
+++ b/c/151_esMatrizIdentidad.cpp
@@ -0,0 +1,28 @@
+#include <iostream>
+
+void solveMatrix(int size) {
+ int value;
+ int wrong = 0;
+ for (int row = 0; row < size; row++) {
+ for (int col = 0; col < size; col++) {
+ std::cin >> value;
+ if ( (col == row && value != 1) || (col != row && value != 0) ) {
+ wrong = 1;
+ }
+ }
+ }
+ if (wrong)
+ std::cout << "NO\n";
+ else
+ std::cout << "SI\n";
+}
+
+int main() {
+ int size;
+ std::cin >> size;
+ while (size != 0) {
+ solveMatrix(size);
+ std::cin >> size;
+ }
+ return 0;
+}