Matrix Addition









Input:Two matrix data
Output: Summation of matrix
Sample Input: First matrix: 1  1  1
                                            1  1   1
                  Second  matrix: 1  1  1
                                            1  1   1
Output: 2   2   2
             2   2    2
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
//Matrix Addition

#include<stdio.h>
int main()
{
int a[10][10],i,j,r,c,b[10][10],d[10][10];
int r1,c1;
printf("Enter the row of a  First  matrix:");
scanf("%d",&r);
printf("Enter the column of a  matrix:");
scanf("%d",&c);


for(i=1;i<=r;i++)
{
    for(j=1;j<=c;j++)
    {
        printf("Enter element a%d%d: ",i,j);
           scanf("%d",&a[i][j]);
}
printf("\n");


}
printf(" The  output Matrix is:\n");

for(i=1;i<=r;i++)
{
    for(j=1;j<=c;j++)
{

printf("%d ",a[i][j]);
}

printf("\n");
}


printf("Enter the row of a Second   matrix:");
scanf("%d",&r1);
printf("Enter the column of a  Second  matrix:");
scanf("%d",&c1);


for(i=1;i<=r1;i++)
{
    for(j=1;j<=c1;j++)
    {
        printf("Enter element a%d%d: ",i,j);
           scanf("%d",&b[i][j]);
}
printf("\n");


}

printf(" The  output  of the Second Matrix is:\n");

for(i=1;i<=r1;i++)
{
    for(j=1;j<=c1;j++)
{

printf("%d ",b[i][j]);
}

printf("\n");
}



for(i=1;i<=r1;i++)
{

    for(j=1;j<=c1;j++)
{
d[i][j]=a[i][j]+b[i][j];
}
}


printf(" The  Addition of two  Matrix is:\n");


for(i=1;i<=r1;i++)
{
    for(j=1;j<=c1;j++)
{


printf("%d ",d[i][j]);
}

printf("\n");
}



}


(By :shahimtiyaj)
SHARE

Shah Imtiyaj

Try to know thyself

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

একটি মন্তব্য পোস্ট করুন