Skip to content

Instantly share code, notes, and snippets.

@xyos
Created June 14, 2012 22:26
Show Gist options
  • Save xyos/2933397 to your computer and use it in GitHub Desktop.
Save xyos/2933397 to your computer and use it in GitHub Desktop.
ejercicios varios
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
int x1, y1, x2, y2, i, j;
cout << "ingrese el numero columnas de la primera matriz" << endl;
cin >> x1;
cout << "ingrese el numero filas de la primera matriz" << endl;
cin >> y1;
int matriz1[x1][y1];
for (i = 0; i < x1; i++) {
for (j = 0; j < y1; j++) {
cout << "ingrese la posicion [" << i + 1 << "][" << j +1 << "]"<< endl;
cin >> matriz1[i][j];
}
}
cout << "ingrese el numero columnas de la segunda matriz" << endl;
cin >> x2;
cout << "ingrese el numero filas de la segunda matriz" << endl;
cin >> y2;
int matriz2[x2][y2];
for (i = 0; i < x2; i++) {
for (j = 0; j < y2; j++) {
cout << "ingrese la posicion [" << i + 1 << "][" << j +1 << "]"<< endl;
cin >> matriz2[i][j];
}
}
if (x1 == x2 && y1 == y2) {
int result[x2][y2];
for (i = 0; i < x1; i++) {
for (j = 0; j < y1; j++) {
// aca hacemos la suma
result[i][j] = matriz1[i][j] + matriz2[i][j];
// imprimimos el resultado
cout << result[i][j] << " ";
}
//imprimimos cada cambio de linea
cout << endl;
}
} else {
cout << "las matrices no son iguales" << endl;
/* code */
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment