lesson04 02二維陣列 foreach遍歷

2021-08-14 04:55:32 字數 1340 閱讀 7389

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

,, };

int row = arr.getlength(0);

int column = arr.getlength(1);

int[,] arr2 = new int[column, row];

for(int j = 0; j < row; j++)

}for(int j = 0; j < column; j++)}*/

/*4.2、有乙個3行4列的二維陣列,要求程式設計找出最大元

素,並輸出所在的行和列。

int[,] arr = new int[3, 4] , , };

int row = arr.getlength(0);

int column = arr.getlength(1);

int max = arr[0, 0],x=0,y=0;

for(int j = 0; j < row; j++)}}

console.writeline("最大元素是 存在陣列中的第行第列",max,y+1,x+1);

*//*

* 4.3.求二位陣列(3行3列)的對角線元素之和。

int[,] arr = new int[3, 3] , , };

int sum = 0;

int row = arr.getlength(0);

int column = arr.getlength(1);

for(int j = 0; j < row; j++)}}

console.writeline(sum);

*//*

* 5.1、int intarr = ;用foreach遍歷數

組,求其元素之積。

int sum = 1;

int intarr = ;

foreach(var x in intarr)

console.writeline(sum);

*//*

5.2、string str = 「hello,lanou!」;用foreach遍

歷字串,求字串中包含幾個』l』字元。

string str = "hello,lanou!";

int n=0;

foreach (var x in str)

}console.writeline(n);

*/console.readkey();}}

}

二維陣列 二維陣列和指標

include using namespace std int main 如上面這段程式所示,通過取位址符 指標 p 獲得了變數 a 的位址,那麼解引用符 就可以從 p 中得到變數 a 的值。也就是說,p a和 p a是等價的。p 是變數 a 的位址,從 p 中就可以取出 a 的值。反之,能從 p ...

陣列 二維陣列

一組相同型別的資料組合,是一種引用型別。陣列名稱不是固定的,與其存放的資料的型別有關。如 存放int型別的資料,陣列名稱 int 存放字串資料,陣列名稱 string 存放scanner型別的資料,陣列名稱 scanner陣列中的每個資料,都是這個陣列的元素。1 宣告 元素型別 變數名 元素型別 變...

陣列 二維陣列

陣列,從名字很簡單看出就是數字組合,一堆數 一堆元素 在一起。然後看一下怎麼定義,怎麼初始化。陣列的動態初始化 初始化之後每個元素的儲存內容為其對應資料型別的預設值。資料型別 陣列名 new 陣列型別 大小 int arr new int 5 資料型別 陣列名 new 陣列型別 大小 int arr...