Header Ads Widget

Responsive Advertisement

Addition of 2 Matrix


 

#include<stdio.h>

int main()
{
    int row,col,i,j;
    int a[100][100],b[100][100],c[100][100];
    printf("Enter The Number of Row & Colum of Two Matrix : ");
    scanf("%d%d",&row,&col);
   
//For input The Elements of 1st Matrix :
   
    printf("Enter The First Matrix : ");
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++) {
            scanf("%d",&a[i][j]);
        }
    }
   
//For input The Elements of 2nd Matrix :
   
    printf("Enter The Second Matrix : ");
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++) {
            scanf("%d",&b[i][j]);
        }
    }
   
//For Output The Elements of 1st Matrix :
   
    printf("The First Matrix is :\n ");
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++) {
            printf("%d  ",a[i][j]);
        }
        printf("\n");
    }
   
//For Output The Elements of 2nd Matrix :
  
     printf("The Second Matrix is :\n ");
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++) {
            printf("%d  ",b[i][j]);
        }
        printf("\n");
        printf("\n");
    }

//Addition Formula :

    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            c[i][j]=a[i][j]+b[i][j];
        }
    }

// Output & Print Results :
 
    printf("The Addition is : \n");
    for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {

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

    return 0;
}


Post a Comment

0 Comments