By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

Program (Calculation of Matrix Product)

P: n/a
#include <stdio.h>
#define MAX 100

int main() {
int m, n, /* dimensoes da matriz A */
nb, p, /* dimensoes da matriz B */
i, j, k;
float A[MAX][MAX], B[MAX][MAX], C[MAX][MAX];

printf("Digite as dimensoes (mXn) da matriz A: ");
scanf("%d", &m);
scanf("%d", &n);
printf("Digite a matriz A:\n");
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
scanf("%f", &A[i][j]);

printf("Digite as dimensoes (nXp) da matriz B: ");
scanf("%d", &nb);
scanf("%d", &p);
if (nb != n)
printf("Nao existe o produto da matriz A por B!!");
else {
printf("Digite a matriz B:\n");
for (i = 0; i < n; i++)
for (j = 0; j < p; j++)
scanf("%f", &B[i][j]);

/* calculo do produto */
for (i = 0; i < m; i++)
for (j = 0; j < p; j++){
C[i][j] = 0;
for (k = 0; k < n; k++)
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}

/* impressao do resultado */
printf("Matriz A X B: \n");
for (i = 0; i < m; i++) {
for (j = 0; j < p; j++)
printf("%f ", C[i][j]);
printf("\n");
}
}

return 0;
}

Jan 5 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
This is C++ but it should be easy enough to translate it to C:
http://cap.connx.com/chess-engines/n...h/strassen.zip

Originally, I think it was C (some student project from the internet),
but I went and translated it.

Typical reasoning says that Strassen matrix multiplication only pays
off when the matrix is very large. That typical reasoning is wrong.

It was not clear to me from your post what you were wanting in reply.
Perhaps a code review? Comments for improvements? If you give some
additional feedback, I can probably say something that is actually
helpful.

Jan 5 '07 #2

P: n/a
look this example that uses dynamic memory llocation :
http://www.vandersongold.com.br/downloads/mul_matriz.c

On 5 jan, 17:37, "user923005" <dcor...@connx.comwrote:
This is C++ but it should be easy enough to translate it to C:http://cap.connx.com/chess-engines/n...h/strassen.zip

Originally, I think it was C (some student project from the internet),
but I went and translated it.

Typical reasoning says that Strassen matrix multiplication only pays
off when the matrix is very large. That typical reasoning is wrong.

It was not clear to me from your post what you were wanting in reply.
Perhaps a code review? Comments for improvements? If you give some
additional feedback, I can probably say something that is actually
helpful.
Jan 5 '07 #3

P: n/a

va************@gmail.com wrote:
look this example that uses dynamic memory llocation :
http://www.vandersongold.com.br/downloads/mul_matriz.c
/* aloca as linhas da matriz */

v = calloc (m, sizeof(float *)); /* Um vetor de m ponteiros para float
*/
if (v == NULL) {

printf ("** Erro: Memoria Insuficiente **");

return (NULL);

}

/* aloca as colunas da matriz */

for ( i = 0; i < m; i++ ) {

v[i] = calloc (n, sizeof(float)); /* m vetores de n floats */

if (v[i] == NULL) {

printf ("** Erro: Memoria Insuficiente **");

/*
vector of float pointers v[] was never freed.
individual columns v[j] for j = 0 to i are not freed.
*/
return (NULL);

}

}

Jan 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.