Get Answers to all your Questions

header-bg qa

Write a program to add, subtract, multiply two matrices in c++ ?

Answers (1)

best_answer

/* C Program to perform matrix operations ,matrix addition, matrix subtraction, matrix multiplication – addition */
#include <stdio.h>
int main()

//fill your code
int m, n;
scanf(“0 0”,&m,&n);
int i, j;
int mat1[m][n], mat2[m][n], mat3[m][n];
for(i = 0; i < m; i++)

for(j = 0; j < n; j++)
scanf(“0”,&mat1[i][j]);

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

for(j = 0; j < n; j++)
scanf(“0”,&mat2[i][j]);

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

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

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

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

for(j = 0; j < n; j++)
printf(“0 “, mat3[i][j]);
printf(“ ”);

return 0;

Posted by

Deependra Verma

View full answer