Saturday 30 November 2013

C Program to Perform Matrix addition Using Dynamic Memory Allocation


  This post provides the C Program to add two matrices. The difference with this program is that memory for the matrices is allocated dynamically. This elegant program was written by a friend and that too by taking just a few minutes. 

Figure Below Shows a Sample Output

  Let int * a; be a pointer, r1 be the number of rows of the matrix and c1 be the number of columns of the matrix, then memory allocation is done as follows.

a=(int *)malloc(r1*c1*sizeof(int));


No comments:

Post a Comment