日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

3.12课·········数组

發布時間:2025/3/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 3.12课·········数组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數組:具有相同類型的若干變量按有序的形式組織起來的一種形式。這些按序排列的同類數據元素的集合稱為數組。
定義數組
int[] 變量名 = new int [n];

string[] myStringArray = new string[6];

int[] myArray = new int[] {1, 3, 5, 7, 9};

數組索引號從0開始
一維數組[相同數據類型]
第一種定義方式
int[] shuzu=new int[5];
for (int i = 0; i <= 5;i++ )//用for循環為shuzu賦值
{
shuzu[i] = i + 1;
}
索引從0開始
賦值
shuzu[0] = 1;
shuzu[1] = 2;
shuzu[2] = 3;
shuzu[3] = 4;
shuzu[4] = 5;

第二種定義方式
int[] shuzu=new int[]{1,2,3,4,5};

Console.WriteLine(shuzu[2]);//3

輸入10個人的年齡,并求和

int[] age = new int[10];int sum = 0;for (int i = 0; i < 10; i++){Console.Write("請輸入第" + (i + 1) + "個人的年齡:");age[i]=int.Parse(Console.ReadLine());//獲取這個數并轉換成數值類型放進數組agesum += age[i];}Console.WriteLine("這10個人的年齡之和是" + sum);Console.ReadLine();

?輸入人名放進數組,輸出第五個人的名字

string[] s = new string[10];for (int i = 0; i < 10;i++ ){Console.Write("請輸入第"+(i+1)+"個人的名字:");s[i] = Console.ReadLine();}Console.Write("第五個人的名字是"+s[4]);Console.ReadLine();

?輸入班級人數,根據人數挨個輸入成績,求平均分

Console.Write("請輸入班級人數:");int a = int.Parse(Console.ReadLine());doudouble[] chengji = new double[a];double sum = 0;for (int i = 0; i < a; i++){Console.Write("請輸入第" + (i + 1) + "個人的成績:");chengji[i] = double.Parse(Console.ReadLine());sum += chengji[i];}Console.WriteLine("" + a + "個人的平均分是" + sum / a);?

二維數組
int[,] shuzu = new int[3, 4];
int[,] shuzu = new int[,] {
{1,2,3,4},
{5,6,7,8},
{6,7,8,9}
};

輸入班級人數,將每個人的
語文,數學,英語成績輸入二維數組

Console.Write("請輸入班級人數:");int a = int.Parse(Console.ReadLine());double [,] shuzu = new double [a,3];for (int i = 0; i < a; i++){for (int j = 0; j < 3; j++){if (j == 0){Console.Write("請輸入第"+(i+1)+"個人的語文成績:");}if (j == 1){Console.Write("請輸入第" + (i + 1) + "個人的數學成績:");}if (j == 2){Console.Write("請輸入第" + (i + 1) + "個人的英語成績:");}shuzu[i, j] = double.Parse(Console.ReadLine());}}Console.ReadLine();

打印字:王,企:

string[,] shuzu = new string[,] {
{" ","■","■","■","■","■",""},
{" "," "," ","■","","",""},
{" "," "," ","■","","",""},
{" "," ","■","■","■","",""},
{" "," "," ","■"," "," ",""},
{" "," "," ","■"," "," ",""},
{"■","■","■","■","■","■","■"}
};

for (int i = 0; i < 7; i++){for (int j = 0; j < 7; j++){Console.Write(shuzu[i, j]);}Console.WriteLine();}?

string[,] s = new string[,]{
{" "," "," ","●"," "," "," "},
{" "," ","●"," ","●"," "," "},
{" ","●"," ","●"," ","●"," "},
{"●"," "," ","●"," "," ","●"},
{" ","●"," ","●","●","●"," "},
{" ","●"," ","●"," " ," "," "},
{"●","●","●","●","●","●","●"}
};

for (int i = 0; i < 7; i++){for (int j = 0; j < 7; j++){Console.Write(s[i, j]);}Console.WriteLine();}Console.ReadLine();

?

轉載于:https://www.cnblogs.com/xinghun/p/5269301.html

總結

以上是生活随笔為你收集整理的3.12课·········数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。