Given three integer matrices A(m*n),B(m*n) and C(m*n) . Print the one with more zero elements. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Given three integer matrices A(m*n),B(m*n) and C(m*n) . Print the one with more zero elements.

I just can’t understand how I can just deduce where there are more zero elements. #include<iostream> using namespace std; int main() { int m, n, p, q, l, v , i, j, k; int a[10][10], b[10][10], c[10][10], res[10][10]; cout << "Enter the order of first matrix\n"; cin >> n >> m; cout << "Enter the order of second matrix\n"; cin >> p >> q; cout << "Enter the order of third matrix\n"; cin >> l >> v; if (n != p) { cout <<"Matrix is incompatible for multiplication\n"; } else { cout << "Enter the elements of Matrix-A:\n"; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } cout << "Enter the elements of Matrix-B:\n"; for (i = 0; i < p; i++) { for (j = 0; j < q; j++) { cin >> b[i][j]; } } cout << "Enter the elements of Matrix-C:\n"; for (i = 0; i < l; i++) { for (j = 0; j < v; j++) { cin >> c[i][j]; } } for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { res[i][j] = 0; for (k = 0; k < p; k++) { res[i][j] += a[i][k] * b[k][j]; } } } cout << "The product of the two matrices is:-\n"; for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { cin>> res[i][j]; } cout <<"\n"; } } return 0; }

7th Feb 2023, 11:49 AM
Никита Л
Никита Л - avatar
6 Answers
+ 2
Question is different for your code.. Also Seems it is incomplete code. Save code in playground and share link here. Also mention your clearly with your trouble for sample imput and expected output.
7th Feb 2023, 12:13 PM
Jayakrishna 🇮🇳
+ 2
4,5 nested loops not be needed. Simple way, take array with size 3. When you taken input, if it zero then increment zero count for that matrix. After all, input find max from 3 count. And print correspondent matrix..
7th Feb 2023, 1:52 PM
Jayakrishna 🇮🇳
+ 1
#include<iostream> using namespace std; int main() { int m, n, i, j, k; int a[10][10], b[10][10], c[10][10], res[10][10]; cout << "Enter the rows and columns\n"; cin >> m >> n; cout << "Enter the elements of Matrix-A:\n"; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } cout << "Enter the elements of Matrix-B:\n"; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> b[i][j]; } } cout << "Enter the elements of Matrix-C:\n"; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> c[i][j]; } } --------------------------------------------------------------------- for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { res[i][j] = 0; HERE } } --------------------------------------------------------------------- cout << "The product of the three matrices is:-\n"; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin>> res[i][j]; } cout <<"\n"; }
7th Feb 2023, 12:31 PM
Никита Л
Никита Л - avatar
0
So for sure, this is not a complete code, I am missing a piece of code responsible for finding zero elements. I need the output of a column of three, the one that will show where there are more zero elements
7th Feb 2023, 12:31 PM
Никита Л
Никита Л - avatar
0
For example, I take an input that I have 2x2 matrices (any, but the same size), after which I enter any numbers (as I understand it) and I should have it show a column in which there are more zero elements
7th Feb 2023, 12:37 PM
Никита Л
Никита Л - avatar