From: hackbard Date: Wed, 10 Apr 2002 23:36:17 +0000 (+0000) Subject: fixed matrix_mult.c - works now X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=7d26cede0a579c4b9876f258fa629042f43e00d3;p=my-code%2Fbeginners.git fixed matrix_mult.c - works now --- diff --git a/matrix_mult.c b/matrix_mult.c index 0c5b1ab..f57268d 100644 --- a/matrix_mult.c +++ b/matrix_mult.c @@ -1,6 +1,6 @@ #include -int *pelemente, *pmatrix1, *pmatrix2; +int *pelemente, *pmatrix1, *pmatrix2; void read_matrix ( int *pzeilen, int *pspalten ) { @@ -49,35 +49,54 @@ int z1,z2; int s1,s2; int i,j,k,ergebnis; +/* welcome */ +printf("\nMatrixmultiplikation:\n\n"); + +/* read matrix1 */ +printf("Matrix1:\n"); read_matrix(&z1,&s1); +/* save matrix1 for future use */ pmatrix1=(int *)malloc(z1*s1 * sizeof(int)); -*pmatrix1=*pelemente; +for (i=0;i<(s1*z1);++i) *(pmatrix1 + i)=*(pelemente + i); -free( *pelemente ); +/* freeing memory */ +free( pelemente ); +/* read matrix2 */ +printf("Matrix2:\n"); read_matrix(&z2,&s2); +/* save matrix2 for future use */ pmatrix2=(int *)malloc(z2*s2 * sizeof(int)); -*pmatrix2=*pelemente; - -free( *pelemente ); +for (i=0;i<(s2*z2);++i) *(pmatrix2 + i)=*(pelemente + i); +/* freeing memory */ +free( pelemente ); +/* just calculate if it is defined! */ if ( s1!=z2 ) { - printf("Nicht definiert!\n"); + printf("\n...well, i ll calculate it for you,\n\nestimated finish on the answer of the question of what life is all about:\t2323.Jan.15th\nand by the way, thanx for the fish. :)\n"); return; } +/* allocating memory for target matrix */ + +pelemente=(int *)malloc(z1*s2 * sizeof(int)); +/* calculating matrix product */ for (i=0;i