二维数组定义
C/C++:int a[][]= {{1,1,3,2},{5,9,0,2},{3,4,7,5}};
int **a= {{1,1,3,2},{5,9,0,2},{3,4,7,5}};
C#:二维固定矩阵 int[,] a={{1,1,3,2},{5,9,0,2},{3,4,7,5}};
参差矩阵定义(二维可变数组):int[][] a=new int[3][];
(1)C#下二维数组应用
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace MilArray
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 int[,] a = {{ 1,1,3,2 }, { 5,9,0,2 }, { 3,4,7,5 }};
13 foreach(int i in a)
14 {
15 Console.WriteLine("{0}",i);
16 }
17 }
18 }
19 }
(2)C++(VS2008)下控制台应用程序
1 #include "stdafx.h"
2 #include <iostream>
3
4 using namespace std;
5 int _tmain(int argc, _TCHAR* argv[])
6 {
7 int a[3][4]={{ 1,1,3,2 }, { 5,9,0,2 }, { 3,4,7,5 }};
8 for(int i=0;i<3;i++)
9 {
10 for(int j=0; j<4;j++)
11 {
12 cout<<a[i][j]<<endl;
13 }
14 }
15 return 0;
16 }