+ 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
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?
+ 2
Thanks
+ 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])
+ 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
+ 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
+ 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;
}
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;
}
}
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;
}
}