C Program to add two dimensional matrices

Write a C program to add two-dimensional matrices by fixing the row and column size as 2 using macros?

Multi dimensional array are those type of array, which has a finite number of rows and a finite number of columns. The 2-dimensional array is declared by
Data_type Array_name [row size][column size];

This program takes two matrices of order r*c and stores it in a two-dimensional array. Then, the program adds these two matrices and displays it on the screen.

C Program Code

#include<stdio.h>
#include<stdlib.h>
#define m 2
int main()
{
int i,j;
int a[m][m],b[m][m],c[m][m];
void add(int(*)[m]);

printf(“Enter the elements of matrix 1:”);
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
scanf(“%d”,a[i][j]);
}
}
printf(“Enter 2nd matrix elements:”);
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
scanf(“%d”,b[i][j]);
}
}
printf(“The sum of 2 entered matrices is :”);
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf(“%d”,c[i][j]);
}
printf(“\n”);
}
void add(int c[m][m])
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[i]+b[i][j];
}

}

 

Leave a comment

We are the best Embedded Training Institutes in Bangalore with 100% job placement record. Our top most priority is to put more and more focus on practical aspects of the Training. We believe if the student is good with practical knowledge he can crack any interview he/she wants. We also promote the meritorious students and those who are in need but can't afford the expensive training in the other institutes are also welcomed at Professional Institute.

It is needless to say that there are many institute which provides Embedded Training in Bangalore but most of them focus on the quantity of the course but we focus majorly on the quality of the education. The reason is very simple, those institute have profit as their main motive but we are mostly concerned with the future of the students. That's why we charge very minimal fees from students.

PTInstitute © 2017 All rights reserved.