C Program to add matrices using pointer
Program
#include<stdio.h>
void main()
{
int a[10][10], b[10][10], c[10][10];
int m, n, i, j;
printf("Enter size of the matrix\n");
scanf("%d %d", &m, &n);
printf("Enter elements of matrix 'a' of size %d\n", (m * n));
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
scanf("%d", (*(a + i) + j));
printf("Enter elements of matrix 'b' of size %d\n", (m * n));
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
scanf("%d", (*(b + i) + j));
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
(*(*(c + i) + j)) = (*(*(a + i) + j)) + (*(*(a + i) + j));
printf("The sum of matrix is:\n");
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
printf("%d\t", (*(*(c + i) + j)));
}
printf("\n");
}
}
Output
$ gcc add-matrix-pointer.c
[koushik@localhost Documents]$ ./a.out
Enter size of the matrix
3
3
Enter elements of matrix 'a' of size 9
12
32
14
15
73
24
27
35
42
Enter elements of matrix 'b' of size 9
54
62
82
54
32
44
23
11
91
The sum of matrix is:
24 64 28
30 146 48
54 70 84