Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, September 10, 2022

C Program to Add Two Matrices Using 2D Array

 C Program to Add Two Matrices Using 2D Array


#include<stdio.h>

#include<conio.h>

main()

{

int i,j,mat1[3][3],mat2[3][3],sum[3][3];

printf("enter the elements for matrix first\n");

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

 {

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

     {

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

     }

 }

 printf("enter the elements for matrix second\n");

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

 {

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

     {

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

     }

 }

/*process of adding matrix 1 and matrix 2*/

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

 {

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

     {

       sum[i][j]=mat1[i][j]+mat2[i][j];

     }

 }

printf("the sum of two matrix is:\n");

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

    {

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

{

   printf("%d\t",sum[i][j]);

}

      printf("\n");

    }

getch();

}


Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages