0

Почему не работает?

Заполнение и вывод массива, не понятно

18th Dec 2020, 10:09 AM
Vladimir Plakhotnichenko
Vladimir Plakhotnichenko - avatar
2 Answers
0
#include <iostream> using namespace std; int main() { const int rows = 6; const int cols = 6; float matrix[cols][rows] = { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, }; //введите код сюда for(int i =0; i < rows ; ++i){ for (int j=0; i < cols ; ++j){ matrix [i][j] = 1; } } for(int i =0; i < rows ; ++i){ for (int j=0; i < cols ; ++j){ cout << matrix [i][j]; } cout << endl; } return 0; }
18th Dec 2020, 10:09 AM
Vladimir Plakhotnichenko
Vladimir Plakhotnichenko - avatar
0
Your inner loop uses <i> in loop condition, it should be using <j> instead. for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) // for (int j = 0; i < cols; ++j) { matrix[i][j] = 1; } } for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) // for (int j = 0; i < cols; ++j) { cout << matrix[i][j]; } cout << endl; }
18th Dec 2020, 11:12 AM
Ipang