数组分为一维数组,二维数组,多为数组
Posted 幸福的谎言
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组分为一维数组,二维数组,多为数组相关的知识,希望对你有一定的参考价值。
//一维数组【相同数据类型】 //第一种定义方式 //int[] shuzu = new int[5]; //for (int i = 0; i < 5; i++) //{ // shuzu[i] = i + 1; //} // //索引从0开始 // //赋值 // //shuzu[0] = 1; // //shuzu[1] = 2; // //shuzu[2] = 3; // //shuzu[3] = 4; // //shuzu[4] = 5; // ////shuzu[5] = 6; // ////shuzu[6] = 7; // Console.WriteLine(shuzu[4]); //第二种定义方式 //int[] shuzu = new int[] { 1,2,3,4,5 }; //Console.WriteLine(shuzu[2]); //从控制台输入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()); // sum += age[i]; //} //Console.WriteLine(sum); //输入人名放进数组,输出第5个人的姓名 //Console.Write("请输入有几个人:"); //int a = int.Parse(Console.ReadLine()); //string [] name =new string [a]; //for (int i = 0; i < a;i++ ) //{ // Console.Write("请输入第" + (i + 1) + "个人的姓名:"); // name[i] = Console.ReadLine(); //} //Console.WriteLine(name[4]); //输入班级人数,根据人数, //挨个输入成绩,求平均分 //Console.Write("请输入班级人数:"); //int a = int.Parse(Console.ReadLine()); //double [] fen = new double [a]; //double sum = 0; //for (int i = 0; i < a;i++ ) //{ // Console.Write("请输入第"+(i+1)+"个人的分数:"); // fen[i] = double.Parse(Console.ReadLine()); // sum += fen[i]; //} //Console.WriteLine("班级平均分为:"+sum/a); //二维数组 //int[,] shuzu = new int[3, 4]; //int[,] shuzu = new int[,] { //{1,2,3,4}, //{5,6,7,8}, //{6,7,8,9} //}; //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(); //} //输入班级人数,将每个人的 //语文,数学,英语成绩输入二维数组 //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(); //三维数组 //int[, ,] shuzu = new int[3, 2, 4]; //{ // { // {,,,}, // {,,,} // }, // { // {,,,}, // {,,,} // }, // { // {,,,}, // {,,,} // } //};
以上是关于数组分为一维数组,二维数组,多为数组的主要内容,如果未能解决你的问题,请参考以下文章
php中:计算任意一维数字数组的奇数个数、偶数个数?代码怎么写.
C 语言数组 ( 验证二维数组内存是线性的 | 打印二维数组 | 以一维数组方式打印二维数组 | 打印二维数组值和地址 )