码迷,mamicode.com
首页 > 编程语言 > 详细

二维数组

时间:2014-12-18 11:35:06      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:ar   for   on   ad   line   new   br   it   string   

//二维数组
int[,] second = new int[2,3]//有两个长度为三的一维数组
{
{3,2,5},
{6,7,8}
};
int[] shu=new int[3]{3,2,5};//一维数组中的三个数

second[0, 1] = 9;
second[1, 0] = 4;

//让数组横向显示
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3;j++ )
{
Console.Write(second [i,j]);
}
Console.Write("\n");
}

foreach (int a in second)
{
Console.WriteLine(a);
}
*/

//输入人数,姓名身高年龄,求平均年龄,身高降序排列
Console.Write("请输入人数:");
int n = int.Parse(Console.ReadLine());

string[,] shuzu = new string[n, 3];
decimal sum = 0;
for (int i = 0; i < n; i++)
{
Console.Write("姓名");
shuzu[i, 0] = Console.ReadLine();
Console.Write("年龄");
shuzu[i, 1] = Console.ReadLine();
sum += decimal.Parse(shuzu[i, 1]);
Console.Write("身高");
shuzu[i, 2] = Console.ReadLine();
}
decimal avg = sum / n;

for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (decimal.Parse(shuzu[i, 2]) < decimal.Parse(shuzu[j, 2]))
{
string zhong;
zhong = shuzu[i, 0];
shuzu[i, 0] = shuzu[j, 0];
shuzu[j, 0] = zhong;

string zhong1;
zhong1 = shuzu[i, 1];
shuzu[i, 1] = shuzu[j, 1];
shuzu[j, 1] = zhong1;

string zhong2;
zhong2 = shuzu[i, 2];
shuzu[i, 2] = shuzu[j, 2];
shuzu[j, 2] = zhong2;
}
}
}


for (int i = 0; i < n; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(shuzu[i, j] + " ");
}
Console.Write("\n");
}
Console .ReadLine();

二维数组

标签:ar   for   on   ad   line   new   br   it   string   

原文地址:http://www.cnblogs.com/liuyuwen900326/p/4171142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!