Addition of Two Matrices Using Pointers
Addition of Two Matrices Using Pointers
#include<stdio.h>
void add(int *,int *,int,int);
void main()
{
int a[3][3],b[3][3],i,j,r,c;
printf("Enter the row and column of the array");
scanf("%d%d",&r,&c);
printf("\nEnter the elements of the 'a'array");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",(&a[0][0]+i*c+j));
printf("\nEnter the elements of the 'b'array");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",(&b[0][0]+i*c+j));
add(*a,*b,r,c);
}
void add(int *p,int *q,int r,int c)
{
int i,j,d[3][3];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
d[i][j]=*(p+i*c+j)+*(q+i*c+j);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d\t",d[i][j]);
printf("\n");
}}