Saturday, May 21, 2011

C program for Addition of matrix

int main()
{
int a[20][20],b[20][20],t[20][20],i,j,k,l,m,n,o,p,c,d,e,f;


printf("\nEnter the no of rows in the array 1");
scanf("%d",&c);
printf("\nEnter the no of columns in the array 1");
scanf("%d",&d);

printf("Enter the matrix");
for(i=0;i {
for(j=0;j scanf("%d",&a[i][j]);
}

printf("\nEnter the no of rows in the array 2");
scanf("%d",&e);
printf("\nEnter the no of columns in the array 2");
scanf("%d",&f);
printf("Enter the matrix");
for(k=0;k {
for(l=0;l scanf("%d",&b[k][l]);
}
if(c==e||d==f)
{
for(m=0;m {
for(n=0;n t[m][n]=a[m][n]+b[m][n];
}
}
else printf("The summation is not possible because no of rows and columns of the two arrays is not same");
printf("The matrix after addition is");
for(o=0;o { printf("\n");
for(p=0;p printf("%d ",t[o][p]);
}
system("pause");
return 0;
}

No comments:

Post a Comment