Write a program to add 2 matrices. (Double Dimension Arrays)

/* Write a program to add 2 matrices.

(Double Dimension Arrays)*/

#include <stdio.h>

void main()

{

    int amat[3][3],bmat[3][3],cmat[3][3],i,j;

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

            printf("Enter the value of Matrix A [%d][%d] : ",i+1,j+1);

            scanf("%d",&amat[i][j]);

        }

    }

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

            printf("Enter the value of Matrix B [%d][%d] : ",i+1,j+1);

            scanf("%d",&bmat[i][j]);

        }

    }

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

            cmat[i][j]=amat[i][j]+bmat[i][j];

        }

    }

    printf("Matrix A\n");

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

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

        }

        printf("\n");

    }

    printf("Matrix B\n");

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

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

        }

        printf("\n");

    }

    printf("Matrix C\n");

    for(i=0;i<3;i++)

    {

        for(j=0;j<3;j++)

        {

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

        }

        printf("\n");

    }

    getch();

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.