• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

C语言数组:二位数组使用示范

OC/C/C++ 水墨上仙 1569次浏览

C语言数组:二位数组使用演示

#include <stdio.h>
void show_2d_array(int array[][10], int rows)
 {
   int i, j;
   for (i = 0; i < rows; i++)
     for (j = 0; j < 10; j++)
       printf("array[%d][%d] = %d\n", i, j, array[i][j]);
 }
int main(void)
 {
   int a[1][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
   int b[2][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
                   {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}};
   int c[3][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
                   {11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
                   {21, 22, 23, 24, 25, 26, 27, 28, 29, 30}};
   show_2d_array(a, 1);
   show_2d_array(b, 2);
   show_2d_array(c, 3);
return 1;
 }

输出结果

array[0][0] = 1
array[0][1] = 2
array[0][2] = 3
array[0][3] = 4
array[0][4] = 5
array[0][5] = 6
array[0][6] = 7
array[0][7] = 8
array[0][8] = 9
array[0][9] = 10
array[0][0] = 1
array[0][1] = 2
array[0][2] = 3
array[0][3] = 4
array[0][4] = 5
array[0][5] = 6
array[0][6] = 7
array[0][7] = 8
array[0][8] = 9
array[0][9] = 10
array[1][0] = 11
array[1][1] = 12
array[1][2] = 13
array[1][3] = 14
array[1][4] = 15
array[1][5] = 16
array[1][6] = 17
array[1][7] = 18
array[1][8] = 19
array[1][9] = 20
array[0][0] = 1
array[0][1] = 2
array[0][2] = 3
array[0][3] = 4
array[0][4] = 5
array[0][5] = 6
array[0][6] = 7
array[0][7] = 8
array[0][8] = 9
array[0][9] = 10
array[1][0] = 11
array[1][1] = 12
array[1][2] = 13
array[1][3] = 14
array[1][4] = 15
array[1][5] = 16
array[1][6] = 17
array[1][7] = 18
array[1][8] = 19
array[1][9] = 20
array[2][0] = 21
array[2][1] = 22
array[2][2] = 23
array[2][3] = 24
array[2][4] = 25
array[2][5] = 26
array[2][6] = 27
array[2][7] = 28
array[2][8] = 29
array[2][9] = 30


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明C语言数组:二位数组使用示范
喜欢 (0)
加载中……