Enter a two-dimensional array in C by following these steps: define the array (specify the number of rows and columns); use a nested loop to iterate over the array elements, and use the cin stream to read user input.
How to input a two-dimensional array in C
In C, you can input a two-dimensional array through the following steps:
1. Define the array
<code class="cpp">int arr[行数][列数];</code>
Number of rows
Specify the number of rows in the array, Number of columns
Specify the array number of columns. 2. Use nested loops to input array elements
<code class="cpp">for (int i = 0; i < 行数; i++) { for (int j = 0; j < 列数; j++) { cin >> arr[i][j]; } }</code>
cin
stream to read user input. Example:
Input a 3x4 two-dimensional array:
<code class="cpp">int main() { int arr[3][4]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { cin >> arr[i][j]; } } return 0; }</code>
Notes:
The above is the detailed content of How to input two-dimensional array in c++. For more information, please follow other related articles on the PHP Chinese website!