+ 2

Multi-Dimensional Arrays - stuck on code

You are a movie theater manager. You are given a two-dimensional array with 6 rows and 6 columns - 36 elements with 0 value, that represent empty theater seats. All 36 tickets for session were sold, so you need to identify all of the seats with value 1. Write a program that replaces all 0 values in the given array by 1 and outputs the resulting matrix. All I got is change 0 to 1 in the first column. How do I do the rest? https://www.sololearn.com/learning/1051/1629/2857/1

18th Feb 2021, 9:04 PM
Marina Bruzgelevičė
Marina Bruzgelevičė - avatar
9 Answers
+ 6
for (int rows = 0; rows < 6; rows++) { for (int cols = 0; cols < 6; cols++) { cout << matrix[rows][cols] + 1; also works. Is one better than the other as far as functionality?
23rd May 2021, 5:04 PM
Lexx
Lexx - avatar
+ 2
Thanks
18th Feb 2021, 10:05 PM
Marina Bruzgelevičė
Marina Bruzgelevičė - avatar
+ 2
import numpy as np data = np.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) row = int(input()) data = data.reshape(6,5) print(data[row])
6th Apr 2022, 7:05 PM
Raxmonjon Yusubjanov
+ 1
#include <iostream> using namespace std; int main() { string arr[3][3] = { {"Python", "JS", "C++"}, {"PHP", "SQL", "Java"}, {"C#", "Swift", "Kotlin"}, }; // your code goes here cout<<arr[0][2]<<endl; return 0; } Good Luck
25th Jan 2022, 4:37 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 1
#include <iostream> using namespace std; int main() { int rows = 6; int cols = 6; float matrix[rows][cols] = { {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}, }; // your code goes here for (int rows = 0; rows < 6; rows++) { for (int cols = 0; cols < 6; cols++) { cout << matrix[rows][cols] + 1; } } return 0; } Good Luck
25th Jan 2022, 4:39 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 1
#include <iostream> using namespace std; int main() { string arr[3][3] = { {"Python", "JS", "C++"}, {"PHP", "SQL", "Java"}, {"C#", "Swift", "Kotlin"}, }; // your code goes here cout<<arr[0][2]<<endl; return 0; }
3rd Jan 2023, 1:44 AM
ZARIF JORAYEV
ZARIF JORAYEV - avatar
0
int i, j; for (i = 0; i < rows; i++){ for (j = 0; j < cols; j++){ matrix[i][j] = 1; cout << matrix[i][j] << endl; } }
26th Aug 2021, 9:10 AM
Zijun FANG
Zijun FANG - avatar
0
agree with the options above. but I would add if function. // your code goes here for (int x=0; x<rows;x++){ for(int y=0; y<cols;y++) { cout << matrix[rows][cols]+1; if(y>4) cout << endl; } }
16th Feb 2022, 11:33 AM
Алексей Копотилкин
Алексей Копотилкин - avatar