Plz help me! matrices C++

Status
Not open for further replies.

antmiu2

Distinguished
Dec 16, 2008
116
0
18,680
please guys im desperate i have a homework from collage.. about matrices

1. Do a program that can do the subtraction of two-dimensional tables. (With creativity, the code is not look to the example). (code below, ex.)

2. Make a charming, creative, passionate and chulííísimmo program that performs the sum of two matrices, but this time using a three-dimensional formation, rather than three dimensional. The 1st cover a rate of 3 tables. The 2nd reference index row number, and the 3rd, the number of columns.

sorry for the crappy english.. this was all in spanish...

here an example of one the adds two matrices:

#include <stdio.h>
#include<conio.h>
#include <math.h>
#define MAXFIL 20
#define MAXCOL 30

/ * Definition of symbolic constant indicating the maximum number of rows and columns * /

void leerentrada(int a[] [MAXCOL], int nfilas, int ncols);
void calcularsuma(int a[] [MAXCOL], int b[] [MAXCOL], int c[] [MAXCOL], int nfila, int ncols);
void escribirsalida(int c[] [MAXCOL], int nfilas, int ncols);

/ / Note that the functions were declared before the main, and that symbolic constants are always uppercase.

main()
{
int nfilas, ncols;
int a[MAXFIL] [MAXCOL], b[MAXFIL] [MAXCOL], c[MAXFIL] [MAXCOL];

printf("Cuantas filas ? ");
scanf("%d", &nfilas);
printf("Cuantas columnas ? ");
scanf("%d", &ncols);

printf("\n\nPrimera Tabla :\n");
leerentrada(a, nfilas, ncols);

printf("\n\nSegunda Tabla :\n");
leerentrada(b, nfilas, ncols);

calcularsuma(a, b, c, nfilas, ncols);

printf("\n\nSuma de los elementos :\n\n");
escribirsalida(c, nfilas, ncols);
}

/ * Read an entire table * /


void leerentrada(int a[] [MAXCOL], int m, int n)
/ * note that here the initial statements of defined functions do not end in a semicolon * /

{
int fila, col;
for (fila = 0; fila < m; ++fila)
{
printf("\nIntroducir datos para la fila No. %2d\n", fila + 1);

for (col = 0; col < n; ++col)
scanf("%d", &a[fila] [col] );
}
return;
}
/ * Sum of the two tables of integers * /

void calcularsuma(int a[] [MAXCOL], int b[] [MAXCOL], int c[] [MAXCOL], int m, int n)
/ * No semicolon * /
{
int fila, col;
for (fila = 0; fila < m; ++fila)
for (col = 0; col < n; ++col)
c[fila] [col] = a[fila] [col] + b[fila] [col];
return;
}

/ * Now, write the result of the sum of the table * /

void escribirsalida(int a[] [MAXCOL], int m, int n)
/ * No semicolon * /
{
int fila, col;
for (fila = 0; fila < m; ++fila)
{
for (col = 0; col < n; ++col)
printf("%4d", a[fila] [col]);
printf("\n");
}
getch();

}

thats the one she gave as example

i need this by friday or im doomed!
 
Status
Not open for further replies.