![sahana](https://www.crazyengineers.com/img/avatar.jpg)
Member • Mar 16, 2008
Member • Mar 16, 2008
Member • Mar 16, 2008
When you say pointers, do you meant that the matrices are implemented using linked list? Could you please provide more details on how the matrices are implemented.sahanai have to multiply 2 n*m matrices using pointers
Member • Mar 17, 2008
Member • Mar 17, 2008
#include<stdio.h> #include<conio.h> main() { int mtrx1[5][5],mtrx2[5][5],product[5][5],ro1,ro2,col1,col2; unsigned short int posblty; static unsigned short int call_main = 0; if(call_main == 0 || call_main % 10 == 0) { clrscr(); printf("\nThis program will calculate the product of two matrices"); printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } call_main++; getnum(&ro1,1); getnum(&col1,3); getnum(&ro2,2); getnum(&col2,4); posblty = is_posble(col1,ro2); if(!posblty) { getch(); repeat(); } getmatrix(mtrx1,ro1,col1,1); getmatrix(mtrx2,ro2,col2,2); multiply(mtrx1,mtrx2,product,ro1,col2,col1); print_matrix(product,ro1,col2); find_trace(product,ro1,col2); repeat(); } getnum(num,message) int *num,message; { do { switch(message) { case 1: printf("\nEnter the number of rows in matrix 1:"); break; case 2: printf("\nEnter the number of rows in matrix 2:"); break; case 3: printf("\nEnter the number of columns in matrix 1:"); break; case 4: printf("\nEnter the number of columns in matrix 2:"); break; default: printf("\nEnter a number:"); } scanf("%d",num); } while(*num > 5); return; } is_posble(col_1,row_2) int row_2,col_1; { if(col_1 != row_2) { printf("\nThe multiplication of given matrices is not possible"); return(0); } else { return(1); } } getmatrix(array,row,column,mtrx_num) int *array[5],row,column,mtrx_num; { int i,j; printf("\nEnter matrix %d\n",mtrx_num); for(i = 0;i < row;i++) { for(j = 0;j < column;j++) { scanf("%d",array+(5*i+j)); } } return; } multiply(matrix1,matrix2,product,l,m,n) int *matrix1[5],*matrix2[5],*product[5],l,m,n; { int i,j,k,temp1,temp2,temp3; for(i=0;i < l;i++) { for(j = 0;j < m;j++) { *(product+(5*i+j)) = 0; for(k = 0;k < n;k++) { temp1 = *(matrix1+(5*i+k)); temp2 = *(matrix2+(5*k+j)); temp3 = *(product+(5*i+j)); *(product+(5*i+j)) = temp1 * temp2 + temp3; } } } return; } print_matrix(array,row,col) int *array[5]; { int i,j; printf("\nThe product is :"); for(i = 0;i < row;i++) { printf("\n"); for(j = 0;j < col;j++) { printf("%5d \t",*(array+(5*i+j))); } } return; }
Member • Mar 18, 2008