0

Task is to form one dimention array "B" that wil hold only positive elements from the given matrix sorted in ascending order

/*Input First line N and M (1<=N,M<=100). Then NxM table is given(all number are integers) Output First line have to contain total number of positive elements in the matrix. The next line have to contain all positive elements from the matrix. Sample input: 3 3 1 0 1 3 -1 0 0 -1 -1 Sample output: 3 1 1 3 What is wrong ?*/ #include <iostream> using namespace std; int main() { int n, m, p = 0; cin >> n >> m; int aza[100][100]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> aza[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (aza[i][j] > 0) { p++; //use the counter to find how many numbers greater than "0" } } } cout << p << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (aza[i][j] > 0) { cout << aza[i][j] << " "; } } } return 0; }

3rd Oct 2020, 11:26 AM
Azat Malgazhdar
Azat Malgazhdar - avatar
1 Réponse
0
Whats wrong you are getting..? It giving the output for sample correctly..
3rd Oct 2020, 11:40 AM
Jayakrishna 🇮🇳