2021-07-08

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.

Use nested for-loops to iterate over two-dimensional matrix.

//my code
#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},
    };
    for(int x=0;x<6;x++){
       for(int y=0;y<6;y++){
       matrix[x][y]=1;
     	  cout<<matrix[x][y];
     	  
        }
       cout<<endl;
    }
    

	return 0;
}
上一篇:多线程实现30个人抢五个座位


下一篇:差分数组+LeetCode1109