• Miércoles 15 de Mayo de 2024, 06:32

Autor Tema:  Problema Con Multiplicacion De Matrices  (Leído 4682 veces)

tix1000

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Problema Con Multiplicacion De Matrices
« en: Domingo 18 de Noviembre de 2007, 17:02 »
0
Espero me puedan ayudar compañeros, me encargaron hacer un programa que primero sumara,luego restara, luego empezamos a usar funciones, hasta aqui todo hiba bien bueno ahora a ese programa lo que tiene que hacer es multiplicar 2 matrices, el codigo en su mayoria ya casi esta terminado, casi lo unico que me falta es donde voy a insertar la orden que se va encargar de hacer la multiplicacion, ya que por mas que le busco no encuentro, aparte de que esto de la programacion no se me da muy bien.

Borland c++ 4.5



#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int mata[10][10];
int matb[10][10];
int matc[10][10];
int x,y,n,m,m1,p;

void leermatriz(int N, int M, int mat[10][10]);
void leermatriz(int N, int M, int mat[10][10])
{
for(x=0;x<=N-1;x=x+1)
  for(y=0;y<=M-1;y=y+1)
   {printf("\n dame el elemento del renglon %d y columna %d ",x+1,y+1);
     scanf("%d",&mat
  • [y]);

    }
  return;
}

void impmatriz(int N, int M, int mat[10][10]);
void impmatriz(int N, int M, int mat[10][10])
{
for(x=0;x<=N-1;x=x+1)
  {
   printf("  \n");
  for(y=0;y<=M-1;y=y+1)
   {printf("%d  ",mat
  • [y]);

    }
 }
  return;
}


void calsuma(int N,int M,int mata1[10][10],int matb1[10][10],int mat[10][10]);
void calsuma(int N,int M,int mata1[10][10],int matb1[10][10],int mat[10][10])
/* Calculo de la suma  */
{
for ( x=0;x<=N-1;x=x+1)
 for (y=0;y<=M-1;y=y+1)
 { mat
  • [y]=mata1
  • [y]+matb1
  • [y];

 }
   return;
}

void calresta(int N,int M,int mata1[10][10],int matb1[10][10],int mat[10][10]);
void calresta(int N,int M,int mata1[10][10],int matb1[10][10],int mat[10][10])
/* Calculo de la suma  */
{
for ( x=0;x<=N-1;x=x+1)
 for (y=0;y<=M-1;y=y+1)
 { mat
  • [y]=mata1
  • [y]-matb1
  • [y];

 }
   return;
}

main()
{
clrscr;
printf("\n¿cuantos renglones tiene la matriz  A? ");
scanf("%d",&n);
printf("\n¿cuantas columnas tiene la matriz A? ");
scanf("%d",&m);
printf("\n¿cuantos renglones tiene la matriz  B? ");
scanf("%d",&m1);
printf("\n¿cuantas columnas tiene la matriz B? ");
scanf("%d",&p);
if (m != m1)
  {printf("\n No se puede realizar la multiplicacion ");
   exit(0);
   }

printf ("\n\nDAME LOS VALORES DE LA MATRIZ A \n");
leermatriz(n,m,mata);
printf ("\n\nDAME LOS VALORES DE LA MATRIZ B \n");
leermatriz(m1,p,matb);






printf ("\n\n   LA MATRIZ A ES \n");
impmatriz(n,m,mata);
printf ("\n\n   LA MATRIZ B ES \n");
impmatriz(m1,p,matb);
printf ("\n\n   LA MATRIZ C ES \n");
impmatriz(n,p,matc);

return 0;
}

Sxepcis

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Problema Con Multiplicacion De Matrices
« Respuesta #1 en: Miércoles 28 de Noviembre de 2007, 13:52 »
0
bueno man tengo el programita en visual c++ 8.0 asi ke aca te dejo el cod tiene algunos comentarios, pero creo q sabras desacerte de ello, es algo obsoleto,viejo xD




/*   Producto de Matrices. (proyecto:  TallerVisualCmm\productoMatrices)
PROBLEMA.  Leer dos matrices de enteros,  Amxn y Bnxp; calcular e imprimir el producto matricial AxB. Asuma:   m = 3,  n = 4,  y  p = 5.
Este programa lee del teclado y escribe en pantalla; en ejecución es posible redireccionar las entradas y salidas hacia disco.                 */

#include <iostream>
using namespace std;  
using namespace System;
#include <iomanip>
#include <conio.h>
#include <dos.h>
int main()
 { Console::Title::set("     UIS  *  EISI  *  22948 Programación Visual C++  *  Programó J. J. León ");
   Console::BackgroundColor::set(ConsoleColor::White);
   const int M = 3,  N = 4,  P = 5;  //  tamaño de arreglos
   int i, j, k, y ;
   float suma, A[M][N], B[N][P], C[M][P];

   Console::Clear();  
   Console::ForegroundColor::set(ConsoleColor::DarkGreen);
   Console::SetCursorPosition(4,1);
   cout  << "\t    PRODUCTO DE MATRICES:  Cmp = (Amn)(Bnp) \n" ;
   Console::ForegroundColor::set(ConsoleColor::DarkMagenta);
   // lectura de las matrices A y B por filas:
   Console::ForegroundColor::set(ConsoleColor::Black);
   cout << "\n        Dame los datos de la matriz A3x4 por filas \n\t";
   for (i = 0; i < M;  i++) {for (j=0;  j < N;  j++) cin >> A[j]; cout <<"\t";}
   cout << "\n        Dame los datos de la matriz B4x5 por filas \n\t";
   for (i = 0; i < N;  i++) {for (j=0; j < P;  j++) cin  >> B[j]; cout <<"\t";}
    // impresión de A y B por filas
   cout  << "\n\t MATRIZ   A  \n";
   for ( i =0;  i < M;  i++)
      { for (j =0;  j< N;  j++)  cout << setw(12) << A[j] ;
   cout << endl; }
   cout  << "\n\t MATRIZ   B  \n";
   for ( i =0;  i < N;  i++)
      { for (j =0;  j < P;  j++) cout << setw(12) << B[j] ;
   cout << endl; }

   //  obtención del producto  AxB
   Console::ForegroundColor::set(ConsoleColor::DarkGreen);
   cout << "\n\n\t Obtencion del Producto AB \n";
   Console::SetCursorPosition(1,40);  
   cout << "\t MATRIZ  AB";     // titulo en area de resultados

   for ( i = 0;  i < M;  i++ )          // i controla filas de AxB
       for ( j = 0;  j < P;  j++)       // j controla columnas de AxB
          { Console::ForegroundColor::set(ConsoleColor::DarkMagenta);
             Console::SetCursorPosition(40,27);
             cout << "Columna " << j << " de B \n";
             y =28;  // oordenada y para ubicar los datos
           for (int f = 0; f < N;  f++)
                 { for (int h = 1; h < 80; h++) cout << " ";
                   Console::SetCursorPosition(40,y+f);
                   cout << setw(12) << B[f][j] << endl;
                  }
            y = y+N-1;
           cout << "\tFila " << i << " de A \n";
           for (int h = 1; h < 80; h++) cout << " ";
           cout << "\r"; //retorno de carro sin avanzar linea
            for (int f = 0; f < N;  f++)
                cout << setw(12) << A[f];  cout  << endl;
         
           Console::ForegroundColor::set(ConsoleColor::Black);
           cout << "\n\tElemento del producto en fila " << i  
               << " columna " << j << endl;
            for (int h = 1; h < 80; h++) cout << " ";
           cout << "\r"; //retorno de carro sin avanzar linea
           Console::ForegroundColor::set(ConsoleColor::DarkMagenta);
           for (int z =0; z < N; z++)
                cout << "\t" << A[z] << "*" << B[z][j] << " + ";

          suma  =  0 ;                  // acumulador para término de AxB
           for ( k=0 ;  k < N;  k++ )    // calcule un elemento
          suma = suma  + A[k] * B[k][j];
           C[j]  =  suma;
            cout << " =   "  << suma;

            Console::SetCursorPosition(j*13, 41+i);
            cout << setw(13)  << suma;
            getch();
         } // fin del proceso de producto

   // impresión de la matriz producto
   Console::SetCursorPosition(1, 40);  
   Console::ForegroundColor::set(ConsoleColor::Black);
   cout  << "\t MATRIZ   AB  \n";
   for (i =0;  i < M;  i++ )
        { for(j = 0; j < P; j++) cout << setw(13) << C[j]; cout << endl;}
   getche();    cout << "\n\t\t\t"; return 0;
 }    //  fin  pgma