X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fbeginners.git;a=blobdiff_plain;f=matrix_mult.c;fp=matrix_mult.c;h=f57268da12e3ef24f797a659180ea1653ca25bce;hp=0c5b1ab0026d2299663f70c14c6af71ffe3b98e7;hb=7d26cede0a579c4b9876f258fa629042f43e00d3;hpb=3264a81c4bad527e3eed3e15f1086a4f2747a576 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