• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅
C/C++与C#区别(5)

二维数组定义

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 }


 


 

posted on 2011-11-30 16:54  lovemu  阅读(289)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3