zoukankan      html  css  js  c++  java
  • 二维数组

    //二维数组
    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(" ");
    }

    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(" ");
    }
    Console .ReadLine();

  • 相关阅读:
    Go语言操作etcd
    grafana使用
    Java整理
    Go操作MySQL
    Go语言操作Redis
    es
    influxDB
    gopsutil
    Java基础之(三):IDEA的安装及破解 lyl
    ClojureScript 点访问格式
  • 原文地址:https://www.cnblogs.com/liuyuwen900326/p/4171142.html
Copyright © 2011-2022 走看看