troubleshooting Question

how to convert this program to  pointer based multiplication

Avatar of indiangeek
indiangeek asked on
C
6 Comments1 Solution192 ViewsLast Modified:
I wrote a program of simple 2D matrix multiplication is c.  Now I want to use pointer to solve this problem, which I am unable to do sofar.  I want to use pointer in function so that function will return me the pointer value(like using Malloc etc). Here is my original program which is working fine, but I am  need a pointer version of this program so that I can use pointer in function multmat. Please help me to recover it soon!

#include<stdio.h>
void matmult( int a1[][3], int b1[][4], int c1[][4]);
void matprint(int c2[][4]);
int main()
{
 int a[2][3]={{1,3,4},
              {2,0,1}},
     b[3][4]={{1, 2, 3, 1},
              {2, 2, 2, 2},
              {3, 2, 1, 4}},
     c[2][4]={{0, 0, 0, 0},
              {0, 0, 0, 0}};
matmult(a,b,c);
matprint(c);
return 0;
}
                                                                                                                                                             
// This function is used for Matrix multiplication
void matmult( int a1[][3], int b1[][4], int c1[][4])
{
 int i,j,k;
 for(i=0;i<2;i++)
 {
   for(j=0;j<4;j++)
   {
     for(k=0;k<3;k++)
      {
        c1[i][j]+=a1[i][k]*b1[k][j];
      }
   }
 }
}
                                                                                                                                                             
//This function is used to print the matrix product
void matprint(int c2[][4])
{
 int i,j;
for(i=0;i<2;i++)
 {
  for(j=0;j<4;j++)
   {
    printf("%4d",c2[i][j]);
   }
    printf("\n");
 }
}
ASKER CERTIFIED SOLUTION
cup

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros