C program to add two matrix | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Sunday, February 16, 2020

C program to add two matrix | My CS Tutorial

C program to add two matrixes. Addition of two matrixes in c.

In this tutorial we will learn  or discuss that how to write a c program code to add two matrix. In this program we will use arrays.

This c program code will add two matrixes.

In the first user will enter range of rows and columns. After it user enter the elements of first matrix then second matrix.

After it compiler check and exicute the condition and logics and print a new matrix in which both matrixes are added.


C PROGRAM CODE



#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j,rows,col;
  int a1[100][100],a2[100][100],add[100][100];

 printf("\n ENTER THE NUMBER OF ROWS:\n ");
 scanf("%d",&rows);

  printf("\n ENTER THE NUMBER OF COLUMNS:\n ");
 scanf("%d",&col);

 //Taking input for 1st matrix

 printf("\n ENTER FIRST MATRIX:\n");

 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   scanf("%d",&a1[i][j]);
  }
 }

  //Taking input for 2nd matrix

  printf("\n ENTER SECOND MATRIX:\n");

 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   scanf("%d",&a2[i][j]);
  }
 }

 //Addition of matrix

 for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   add[i][j]=a1[i][j]+a2[i][j];
  }
 }

 printf("\n ADDITION OF THESE MATRICES:\n ");

  for(i=0;i<rows;i++)
 {
  for(j=0;j<col;j++)
  {
   printf("%d\t",add[i][j]);
  }

  printf("\n ");
 }

getch();
}


OUTPUT:






Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment