C Program for Matrix Addition Using 2-D Arrays

 #include<stdio.h>


void main()

{

    int matA[10][10], matB[10][10], matC[10][10], rows, cols, r, c;


    printf("\nEnter no. of rows & cols: ");

    scanf("%d%d",&rows,&cols);


    printf("\nEnter matrix 1 of %d x %d: ",rows,cols);

    for(r=0;r<rows;r++)

        for(c=0;c<cols;c++)

            scanf("%d",&matA[r][c]);


    printf("\nEnter matrix 2 of %d x %d: ",rows,cols);

    for(r=0;r<rows;r++)

        for(c=0;c<cols;c++)

            scanf("%d",&matB[r][c]);


    for(r=0;r<rows;r++)

        for(c=0;c<cols;c++)

            matC[r][c] = matA[r][c] + matB[r][c];


    printf("\nMatrix C (Result of Addition) is : ");

    for(r=0;r<rows;r++)

    {

        printf("\n");

        for(c=0;c<cols;c++)

            printf("%d ",matC[r][c]);

    }

}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices