MR PROGRAMATOR

Suma de matrices

/************************************/

/* Nombre del programa : prog12.    */

/* Objetivo: Suma de matrices      */

/* Autor : mrprogramator.es.tl     */

/* Fecha : 22/05/12                */

/***********************************/

#include "stdafx.h"

 

#define MMAX 100

#define NMAX 100

 

/*Inicialización de subprogramas*/

void LeerMatriz(int(*A)[NMAX],int M, int N);

void ImprimirMatriz(int(*A)[NMAX],int M, int N);

void SumarMatriz(int(*A)[NMAX],int M, int N,int *S);

void ImprimirSuma(int *S, int N);

/*Fin de la inicialización de subprogramas*/

 

int main(void)

{

      int N,M,A[NMAX][MMAX],S[NMAX];

      printf("nIntroduce the number of lines :");

      scanf_s("%d",&N);

      printf("nIntroduce the number of columns :");

      scanf_s("%d",&M);

      LeerMatriz(A,M,N);     

      SumarMatriz(A,M,N,S);

      ImprimirMatriz(A,M,N);

      ImprimirSuma(S,N);

      return 0;

}

 

/*Subprogramas*/

void LeerMatriz(int(*A)[NMAX],int M, int N)

{

 int i,j;

 for(i = 0; i<N;i++)

 {

       for(j = 0; j<M; j++)

       {

             printf("nA[%d][%d]: ",i,j);

             scanf_s("%d",&A[i][j]);

       }

 }

}

void ImprimirMatriz(int (*A)[MMAX],int M, int N)

{

 int i,j;

 printf("nTHE MATRIXn");

 for(i = 0; i<N;i++)

 {

       printf("n");

       for(j = 0; j<M; j++)

       {

             printf("%3d ",A[i][j]);

       }

 }

}

void SumarMatriz(int(*A)[NMAX],int M, int N,int *S)

{

 int i,j;

 for(i = 0; i<N; i++)

 {

       S[i] = 0;

 }

 for(i = 0; i<N;i++)

 {

       printf("n");

       for(j = 0; j<M; j++)

       {

             S[i] = S[i] + A[i][j];

       }

 }

}

void ImprimirSuma(int *S, int N)

{

      int i;

      printf("nTHE ADITIONn");

      for(i = 0; i<N; i++)

      {

            printf("n%3d",S[i]);

      }

      printf("n");

}


Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis