How to perform this matrix integral?

How to write a C program to perform matrix multiplication using pointer?

  • Answer:

    void main() { int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q; printf("Enter The Rows And Cloumns And Of The First Matrix:"); scanf("%d %d",&m,&n); printf("\nEnter The Rows And Cloumns And Of The Second Matrix:"); scanf("%d %d",&p,&q); printf("\nEnter Elements Of The First Matrix:\n"); for(i=0;i< m;i++) { for(j=0;j< n;j++) {scanf("%d",&a[i][j]);} } printf("\nEnter Elements Of The Second Matrix:\n"); for(i=0;i< p;i++) { for(j=0;j< q;j++) scanf("%d",&b[i][j]); } printf("The First Matrix Is:\n"); /* Print the first matrix */ for(i=0;i< m;i++) { for(j=0;j< n;j++) printf(" %d ",a[i][j]); printf("\n"); } printf("The Second Matrix Is:\n"); /* Print the second matrix */ for(i=0;i< p;i++) { for(j=0;j< q;j++) printf(" %d ",b[i][j]); printf("\n"); } if(n!=p) { printf("Aborting./nMultiplication Of The Above Matrices Not Possible."); exit(0); } else { for(i=0;i< m;i++) { for(j=0;j< q;j++) { c[i][j] = 0; for(k=0;k< n;k++) { c[i][j] = c[i][j] + a[i][k] * b[k][j]; } } } printf("\nThe Product Of The Two Matrices Is:\n\n"); for(i=0;i< m;i++) { for(j=0;j< q;j++) { printf(" %d ",c[i][j]); } printf("\n"); } } return 0; } -----------------------------------------------------">----------------------------------------------------- The above code is not the solution of Matrix multiplication using pointers. the following code is absolutely correct. void main() {int *a,*b,*c,row1,col1,row2,col2; clrscr(); printf("enter rows of 1at matrix"); scanf("%d",&row1); printf("enter columns of 1at matrix"); scanf("%d",&col1); printf("enter rows of 2nd matrix"); scanf("%d",&row2); printf("enter columns of 2nd matrix"); scanf("%d",&col2); if(col1!=row2) { printf("\nsorry\n"); } else { a = (int *) malloc(row1*col1 * 2); b = (int *) malloc(row2*col2 * 2); c = (int *) malloc(col1*row2 * 2); clrscr(); printf("enter 1st matrix \n"); insert(a,row1,col1); getch(); clrscr(); printf("enter 2st matrix \n"); insert(b,row2,col2); getch(); clrscr(); printf("1st matrix is\n"); display(a,row1,col1); printf("\n2nd matrix is\n"); display(b,row2,col2); prod(a,b,c,row1,col2); printf("\nafter multiplication \n\n\n"); display(c,row1,col2); } getch(); } insert(int *q,int r,int c) {int i,j; for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("\nEnter [%d][%d] element-- ",i,j); scanf("%d",(q+i*c+j)); } } } display(int *q,int r,int c) {int i,j; for(i=0;i<r;i++) { printf("\n"); for(j=0;j<c;j++) { printf("%d\t",*(q+i*c+j)); } } } prod(int *p,int *q,int *z,int r1,int c2) {int i,j,k; for(i=0;i<r1;i++) { for(j=0;j<c2;j++) { *(z+i*c2+j)=0; for(k=0;k<r1;k++) { *(z+i*c2+j)+=*(p+k*2+j)*(*(q+i*c2+k)); } } } } //Designed by Asjad Farrukh.......

wiki.answers.com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.