C program to add two matrices by using pointer | 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....

Monday, February 24, 2020

C program to add two matrices by using pointer | My CS Tutorial


C program to add two matrices by using pointer.
Addition of two matrices by using pointer in c programming.

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

This c program code will add two matrices.

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>
main()
{
 int i,j,rows,col;
  int a1[100][100],a2[100][100],add[100][100];


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

  printf("\n ENTER 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 ABOVE MATRICES:\n ");

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

  printf("\n ");
 }

}


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