Computer Science, asked by shivamagg9117, 11 months ago

Write a program to input any two matrices and print sum of matrices.

Answers

Answered by mohishkhan9996
5

Answer:

hey.... mate ur ans..... is here

#include <stdio.h>

int main()

{

int m, n, c, d, first[10][10], second[10][10], sum[10][10];

printf("Enter the number of rows and columns of matrix\n");

scanf("%d%d", &m, &n);

printf("Enter the elements of first matrix\n");

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

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

scanf("%d", &first[c][d]);

printf("Enter the elements of second matrix\n");

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

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

scanf("%d", &second[c][d]);

printf("Sum of entered matrices:-\n");

for (c = 0; c < m; c++) {

for (d = 0 ; d < n; d++) {

sum[c][d] = first[c][d] + second[c][d];

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

}

printf("\n");

}

return 0;

}

plzz mark as brainlist......XD

Answered by ribhur2102
0

/* program to print sum of two number in the given two matrices */

#include <stdio.h>

#include<conio.h>

void main()

int i,j,m,n,p,q;

int a[5][5] , b[5][5] , c[5][5];

printf("Enter the row and column sizes of matrix - 1 : ");

//Complete the code in for //

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

{

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

{

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

}

}

printf (" Enter the row and column sizes of matrix - 2 : ");

scanf(" %d  %d ", &p, &q );

printf("Enter matrix - 2 %d elements : ", p * q);

// Complete the code in for //

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

{

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

{

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

}

}

printf("The given matrix  - 1 is \n ");

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

{

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

{

printf ( " %d " , a[i][j] );

}

printf("\n");

}

//Code to display Matrix - 1 elements //

printf ("The given matrix - 1 is \n");

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

{

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

{

printf(" %d " , b[i][j]);

}

printf( " \n ");

}

// Code to display matrix - 2 elements //

if (n==p)

{

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

{

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

{

c[i][j] = a[i][j] + b[i][j];

}

}

printf ( " Addition of two matrices is \n ");

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

{

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

{

printf ( "%d " , c[i][j] );

}

printf ( " \n ");

}

}

else

{

printf ( "Addition is not possible \n ");

}

}

Similar questions