Wednesday 11 January 2012

Write a c program to ADD two matrices of order M*N

#include<stdio.h>
#include<conio.h>

void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n;
clrscr();
printf("Enter the order of the matrix::\n");
scanf("%d%d",&m,&n);
printf("Enter the 1st matrix::\n");
for(i=0;i<m;i++)
{
    for(j=0;j<n;j++)
    {
        scanf("%d",&a[i][j]);
    }
}

printf("Enter the 2nd 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("The resultant matrix is::\n");
for(i=0;i<m;i++)
{
    for(j=0;j<n;j++)
    {
        printf("%d ",c[i][j]);
    }
    printf("\n");
}
getch();
}

No comments:

Post a Comment