Skip to content

Instantly share code, notes, and snippets.

@RamonLopezEscudero
Last active February 6, 2016 19:38
Show Gist options
  • Save RamonLopezEscudero/5cb5d2006987d21cf066 to your computer and use it in GitHub Desktop.
Save RamonLopezEscudero/5cb5d2006987d21cf066 to your computer and use it in GitHub Desktop.
Suma de Matrices
#include <stdio.h>
#include <stdlib.h>
int main()
{
/* ---------------------------------- */
int i, j, k;
int n_matrix, n_row, n_col;
/* --------------------------------- */
printf("Programa para realizar sumas matriciales \n \n");
/* Entrada de la cantidad de matrices a operar y sus dimensiones*/
printf("Introduzca la cantidad matrices a operar: ");
scanf("%i", &n_matrix);
printf("Introduzca el numero de renglones: ");
scanf("%i", &n_row);
printf("Introduzca el numero de columnas: ");
scanf("%i", &n_col);
/* --------------------------------- */
float temp_matrix[n_row][n_col], sum_matrix[n_row][n_col];
/* --------------------------------- */
/* Llenar de valores cero el arreglo donde se almacenara la suma matricial */
for (i = 0; i < n_row; i++)
{
for (j = 0; j < n_col; j++)
{
sum_matrix[i][j] = 0.0;
}
}
/* Iteracion de entrada de datos por matriz */
for (i = 0; i < n_matrix; i++)
{
printf("\nValores de la matriz %i", i + 1);
for (j = 0; j < n_row; j++)
{
printf("\nIntroduzca los valores del renglon %i \n", j +1);
for (k = 0; k < n_col; k++)
{
printf("Elemento %i: ", k + 1);
scanf("%f", &temp_matrix[j][k]);
}
}
/* Suma de Matrices */
for (j = 0; j < n_row; j++)
{
for (k = 0; k < n_col; k++)
{
sum_matrix[j][k] = sum_matrix[j][k] + temp_matrix[j][k];
}
}
}
/* Impresion de los resultados */
printf("\nVector Resultado:\n");
for (i = 0; i < n_row; i++)
{
printf("[ ");
for (j = 0; j < n_col; j++)
{
printf("%f ", sum_matrix[i][j]);
}
printf("]\n");
}
printf("\n");
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment