LAB 3

MATRICES FORMULAS
#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() 

cout << "MULTIPLICACION DE MATRICES\n" << endl; 

//INICIAMOS LAS MATRICES EN 0 
int matrizA[3][3] = {}; 
int matrizB[3][3] = {}; 
int matrizC[3][3] = {}; 
int numero = 0; 

//MATRIZ A 

for(int x = 0; x < 3; x++) 
for(int y = 0; y < 3; y++) 

cout << "Ingrese un numero en la matriz A[" << x << "]" << "[" << y << "] = "; 
cin >> numero; 
matrizA[x][y] = numero; 


//MATRIZ B 
cout << endl; 

for(int x = 0; x < 3; x++) 
for(int y = 0; y < 3; y++) 

cout << "Ingrese un numero en la matriz B[" << x << "]" << "[" << y << "] = "; 
cin >> numero; 
matrizB[x][y] = numero; 


//MULTIPLICACION DE MATRICES 

for(int i = 0; i < 3; i++) 
for(int j = 0; j < 3; j++) 
for(int k = 0; k < 3; k++) 
matrizC[i][j] = (matrizC[i][j] + (matrizA[i][k] * matrizB[k][j])); 


//IMPRIME MATRIZ A 
cout << endl << "DISTRIBUCION GRAFICA\n" << "----------------------" << endl << "Matriz A: " << endl; 

for(int i = 0; i < 3; i++) 
{
for(int j = 0; j < 3; j++) 

cout << setw(10) << matrizA[i][j]; 

cout << endl; 


cout << endl << "Matriz B: " << endl; 

//iMPRIME MATRIZ B 
for(int i = 0; i < 3; i++) 
{
for(int j = 0; j < 3; j++) 

cout << setw(10) << matrizB[i][j]; 

cout << endl; 


//iMPRIME RESULTADO 
cout << endl << "\nMultiplicacion de A x B: \n" << endl; 

for(int i = 0; i < 3; i++) 
{
for(int j = 0; j < 3; j++) 

cout << setw(10) << matrizC[i][j]; 

cout << endl; 


cout << endl; 
system("PAUSE"); 
return 0; 
o tambien de la sgte forma:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>

 
void solicitar(int *tam, int m1[10][10], int m2[10][10])
{
  int a,b;
  textcolor(6);
  clrscr();
  cout << "ttIngresa el tamaño de la matriznn";
  cin >> *tam;
 
  for(a=0; a<*tam; a++)
  {
   textcolor(a+10);
   clrscr();
   cout << "nnIngresa la fila " << a+1 << " de la matriz 1n";
   for (b=0; b<*tam; b++)
 cin >> m1[a][b];
 
   cout << "Ingrese la fila " << a+1 << " de la matriz 2n";
   for (b=0; b<*tam; b++)
 cin >> m2[a][b];
 
   }
 
}
void suma_matriz(int *tam_m, int ma1[10][10], int ma2[10][10], int re[10][10])
{
  int a, b;
  for(a=0; a<*tam_m; a++)
   for (b=0; b<*tam_m; b++)
 re[a][b]=ma1[a][b] + ma2[a][b];
 
 
}
void salida_datos(int *tam_matriz, int matriz1[10][10], int matriz2[10][10], int resultado[10][10])
{
 int a, b, r, c;
 textcolor(2);
 clrscr();
 cout << "ttEl resultado de la suma de matrices es:";
 r=5;
 for(a=0; a<*tam_matriz; a++)
 {
  c=8;
  for (b=0; b<*tam_matriz; b++)
  {
   c+=4;
   gotoxy(c,r);
   cout << matriz1[a][b];
 
   c+=20;
   gotoxy(c,r);
   cout << matriz2[a][b];
 
   c+=20;
   gotoxy(c,r);
   cout << resultado[a][b];
 
   c-=40;
  }
  r+=2;
 }
 
 
}
void main()
{
 int tm, mat1[10][10], mat2[10][10], res[10][10];
 char ans='s';
 while(ans=='s')
 {
  solicitar(&tm, mat1, mat2);
  suma_matriz(&tm, mat1, mat2, res);
  salida_datos(&tm, mat1, mat2, res);
  cout << "nnnttDesea calcular otra suma de matrices?ntts=sin";
  cin >> ans;
  ans=tolower(ans);
 }
 cout << "nnttPresione una tecla para finalizar el programa";
 getche();
}

No hay comentarios.:

Publicar un comentario