/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
//PROYECTO 4. CALCULADORA DE MATRICES
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main(){
//DECLARACIÓN DE VARIABLES
int filas, columnas, matrizA[100][100], matrizB[100][100], matrizC[100][100], opcion;
char dato;
do{
system("cls");
//ENTRADA DE DATOS
cout<<" AVISO: AMBAS MATRICES TIENEN IGUAL DIMENSIONES."<<endl;
cout<<"\nDigite la cantidad de filas para ambas matrices: "; cin>>filas;
cout<<"\nDigite la cantidad de columnas para ambas matrices: "; cin>>columnas;
cout<<endl;
//INGRESO DE DATOS PARA LA MATRIZ A
cout<<"--------------------------------MATRIZ A--------------------------------"<<endl;
for(int i=0; i<filas; i++){
for(int j=0; j<columnas; j++){
cout<<"\nIngrese el valor de la posicion "<<"["<<i<<"]["<<j<<"] = "; cin>>matrizA[i][j];
}
}
cout<<endl;
//INGRESO DE DATOS PARA LA MATRIZ B
cout<<"--------------------------------MATRIZ B--------------------------------"<<endl;
for(int i=0; i<filas; i++){
for(int j=0; j<columnas; j++){
cout<<"\nIngrese el valor de la posicion "<<"["<<i<<"]["<<j<<"] = "; cin>>matrizB[i][j];
}
}
//EL USUARIO ELIGIENDO SUMA O RESTA PARA OPERAR AMBAS MATRICES
cout<<endl;
cout<<"Seleccione la operacion deseada: "<<endl;
cout<<"1. Suma."<<endl;
cout<<"2. Resta."<<endl;
cout<<"\nRESPUESTA "; cin>>opcion;
switch(opcion){
case 1:{
//PROCESO PARA SUMAR AMBAS MATRICES
for(int i=0; i<filas;i++){
for(int j=0; j<columnas; j++){
matrizC[i][j] = matrizA[i][j] + matrizB[i][j];
}
}
//MOSTRANDO RESULTADO
cout<<"\nLa suma de ambas matrices es: "<<endl;
for(int i=0; i<filas;i++){
for(int j=0; j<columnas; j++){
cout<<"["<<matrizC[i][j]<<"] ";
}
cout<<"\n";
}
break;
}
case 2:{
//PROCESO PARA RESTAR AMBAS MATRICES
for(int i=0; i<filas; i++){
for(int j=0; j<columnas; j++){
matrizC[i][j] = matrizA[i][j] - matrizB[i][j];
}
}
//MOSTRANDO RESULTADO
cout<<"\nLa resta de ambas matrices es: "<<endl;
for(int i=0; i<filas; i++){
for(int j=0; j<columnas; j++){
cout<<"["<<matrizC[i][j]<<"] ";
}
cout<<"\n";
}
break;
}
//SI EL USUARIO NO HA ESCOGIDO UNA OPCIÓN CORRECTA
default:{
cout<<"\nNo ha seleccionado una operacion valida."<<endl;
break;
}
}
cout<<"\nDesea ingresar otras matrices seleccione si o no (s/n): "; cin>>dato;
}while(dato == 's' || dato == 'S');
getch();
}