Tuesday 13 December 2011

program for addition of two matrices

#include<stdio.h>
main()
{
        int a[10][10],b[10][10],c[10][10],m,n;
        int i,j;
        printf("\n enter the size of the matrix (m*n): ");
        scanf("%d %d",&m,&n);
        printf("\n enter the elements of first matrix: \n");
        for(i=0;i<m;i++)
                for(j=0;j<n;j++)
                        scanf("%d",&a[i][j]);
        printf("\n enter the lements of second matrix: \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]+b[i][j];
        printf("\n the addition matrix is: \n");
        for(i=0;i<m;i++)
        {
                printf("\n");
                for(j=0;j<n;j++)
                        printf("%d ",c[i][j]);
        }

}

No comments:

Post a Comment