Math, asked by krishna291104, 10 months ago

write a program for addition of two matrix in scanner​

Answers

Answered by ajju227
1

Step-by-step explanation:

printf("\nEnter elements of 1st matrix:\n");

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

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

printf("Enter element a%d%d: ", i + 1, j + 1);

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

}

printf("Enter elements of 2nd matrix:\n");

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

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

printf("Enter element a%d%d: ", i + 1, j + 1);

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

}

// adding two matrices

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

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

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

}

// printing the result

printf("\nSum of two matrices: \n");

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

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

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

if (j == c - 1) {

printf("\n\n");

}

}

return 0;

}

Output

Enter the number of rows (between 1 and 100): 2

Enter the number of columns (between 1 and 100): 3

Enter elements of 1st matrix:

Enter element a11: 2

Enter element a12: 3

Enter element a13: 4

Enter element a21: 5

Enter element a22: 2

Enter element a23: 3

Enter elements of 2nd matrix:

Enter element a11: -4

Enter element a12: 5

Enter element a13: 3

Enter element a21: 5

Enter element a22: 6

Enter element a23: 3

Sum of two matrices:

-2 8 7

10 8 6

In this program, the user is asked to enter the number of rows r and columns c. Then, the user is asked to enter the elements of the two matrices (of order r*c).

Mark me as Brainlist if u r satisfied

Answered by Qubze88
2

Step-by-step explanation:

public class Add_Matrix.

int p, q, m, n;

Scanner s = new Scanner(System.

System. out. print("Enter number of rows in first matrix:");

p = s. nextInt();

System. out. print("Enter number of columns in first matrix:");

q = s. nextInt();

System. out. print("Enter number of rows in second matrix:");

....make it brainliest

Similar questions