zoukankan      html  css  js  c++  java
  • 2014-12-16 多维数组

    多维数组:

    int [,] shuzuming=new int[5,3]   //有5个长度为3的一维数组

    二维数组读取时,逗号前的为y轴,逗号后面的为x轴(一维数组)

    int[,] second = new int[2, 3] { { 3, 2, 5 }, { 6, 7, 8 } };

    second[0,1]=9  即为在(1,0)坐标处的值替换为9

     //年龄,身高,姓名,人数,求平均年龄、身高排序

    Console.WriteLine("请输入人数");
                int n=int.Parse(Console.ReadLine());
                string[,] second = new string[n, 3];
                decimal sum=0;
                for(int i=0;i<n;i++)
                {
                    Console.WriteLine("姓名");
                    second[i,0]=Console.ReadLine();
                    Console.WriteLine("年龄");
                    second[i,1]=Console.ReadLine();
                    sum=sum+decimal.Parse(Console.ReadLine());
                    Console.WriteLine("身高");
                    second[i,2]=Console.ReadLine();
                }
                decimal avg = sum / n;
                Console.WriteLine("平均年龄为" + avg);
                for (int i = 0; i < n - 1; i++)
                {
                    for (int j = i + 1; j < n; j++)
                    {
                        if (decimal.Parse(second[i, 2]) < decimal.Parse(second[j, 2]))
                        {
                            string zhong;
                            zhong = second[i, 0];
                            second[i, 0] = second[j, 0];
                            second[j, 0] = zhong;

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

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


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

  • 相关阅读:
    数据库的创建,数据的增删改查
    Ubuntu系统下查看显卡相关信息
    分布式文件系统测试方法与测试工具
    分布式存储产品的测试实践及心得
    sql注入
    web测试项目总结
    Ubuntu系统下使用Jenkins进行项目的自动构建还是项目回滚方法
    Ubuntu系统下Jenkins的git构建基本方法
    Ubuntu系统下在github中新增库的方法
    ADO.NET复习总结(2)--连接池
  • 原文地址:https://www.cnblogs.com/jintuo/p/4167180.html
Copyright © 2011-2022 走看看