Java教程

2021-07-08

本文主要是介绍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;
}
这篇关于2021-07-08的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!