code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

/* Programa de Multiplicacao de Matrizes */

/* Desenvolvido por Joel de Melo MAT 5300 Turma N2-C */

/* e-mail tinnytoon@yahoo.com

Main()

    {

     int M1[149][149], M2[149][149], M3[149][149], a, contl, contc, contN, M, N, P;

     a=0, contl=0, contc=0, contN=0, M=0, N=0, P=0;

     printf("\nPrograma Multiplica Matriz");

     printf("\n\n\nEntre com o numero de linhas e colunas da primeira matriz\n");

     scanf("%d %d",&M,&N);

     if ((0

         {

         printf("Sua primeira matriz e uma %dx%d",M,N);

         printf("\n\nEntre com o numero de colunas da segunda matriz %dx? ",N);

         scanf("%d",&P);

         if(0

             {

             printf("Sua segunda matriz e uma %dx%d",N,P);

             printf("\n\nEntrada dos valorez da primeira Matriz(M1)%dx%d\n",M,N);

             /* Leitura da matriz M1 */

             for(contl=1;contl<=M;contl++)

             { for(contc=1;contc<=N;contc++)

                 {

                 printf("Entre com o valor de a%d%d ",contl,contc);

                 scanf("%d",&a);

                 M1[(contl-1)][(contc-1)]=a;

                 }

                 }

                 /* Imprime matriz M1 */

                 for(contl=1;contl<=M;contl++)

                 { printf("\n");

                 for(contc=1;contc<=N;contc++)

                     {

                     printf("a%d%d=%d ",contl,contc,M1[(contl-1)][(contc-1)]);

                     }

                     }

                     /* Leitura da matriz M2 */

                     printf("\n\nEntrada dos valores da segunda Matriz(M2)%dx%d\n",N,P);

                     for(contl=1;contl<=N;contl++)

                     { for(contc=1;contc<=P;contc++)

                         {

                         printf("Entre com o valor de b%d%d ",contl,contc);

                         scanf("%d",&a);

                         M2[(contl-1)][(contc-1)]=a;

                         }

                         }

                         /* Imprime a matriz M2 */

                         for(contl=1;contl<=N;contl++)

                         { printf("\n");

                         for(contc=1;contc<=P;contc++)

                             {

                             printf("b%d%d=%d ",contl,contc,M2[(contl-1)][(contc-1)]);

                             }

                             }

                             /* Calcula a Matriz M3 que e o produto de M1*M2 e a imprime */

                             printf("\n\nResultado da multiplicacao da matriz M1*M2\n");

                             for(contl=1;contl<=M;contl++)

                             { printf("\n");

                             for(contc=1;contc<=P;contc++)

                                 {

                                 for(contN=1;contN<=N;contN++)

                                     {

                                     M3[contl-1][contc-1]=M3[contl-1][contc-1]+(M1[contl-1][contN-1]*M2[contN-1][contc-1]);

                                     }

                                     printf("c%d%d=%d ",contl,contc,M3[contl-1][contc-1]);

                                     }

                                     }

                                     /* Zerando a Matriz M3 para uso futuro */

                                     for(contl=1;contl<=M;contl++)

                                     { for(contc=1;contc<=P;contc++)

                                         {

                                         M3[contl-1][contc-1]=0;

                                         }

                                         }

                                         getche();

                                         }

                                         }

                                         else

                                          printf(" Vc entrou com valor 0 ou muito alto, tamanho maximo e 150X150");

                                    }