• 3月12日 数组


    数组:

    一维数组:

    第一种定义方式:

    int[] shuzu = new int[5];
                //shuzu[0] = 1;
                //shuzu[1] = 2;
                //shuzu[2] = 3;
                //shuzu[3] = 4;
                //shuzu[4] = 5;
                //Console.WriteLine(shuzu[4]);

    第二种定义方式:

    int[] shuzu = new int[]{1,2,3,4,5};

    //输入班级人数,根据人数,挨个输入成绩,求平均分;
                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);
                Console.ReadLine();

    二维数组:

    //二维数组
                //int[,] shuzu = new int[3, 4];//3个数组,每个数组有4个
                //int[,] shuzu = new int[,] { };

    //输入班级人数,将每个人的
                //语文、数学、英语成绩输入二维数组;
                Console.Write("输入班级人数");
                int a = int.Parse(Console.ReadLine());
                double[,] fen = new double[a, 3];
                for (int i = 0; i < a; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (j == 0)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的语文成绩是:");
                        }
                        if (j == 1)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的数学成绩是:");
                        }
                        if (j == 2)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的英语成绩是:");
                        }
                        fen[i, j] = double.Parse(Console.ReadLine());
                    }
                }
                Console.ReadLine();
     string [,] shuzu = new string[7,7] 
                { 
    
                {"  ","  ","  ",""," "," "," "},
                {"  ","  ",""," ",""," "," "},
                {"  ",""," ",""," ",""," "},
                {"  ","  ","  ",""," "," "," "},
                {"  ","  ","","",""," "," "},
                {"  ","  ","",""," "," "," "},
                {"  ","","","","",""," "},
                
    
                };
               for (int i = 0; i < 7; i++)
               {
                   for (int j = 0; j < 7; j++)
                   {
                       Console.Write(shuzu[i, j]);
                   };
                   Console.WriteLine();
               }
               Console.ReadLine();
                

    三维数组:

    //三维数组
                //int[, ,] shuzu = new int[3, 2, 4];//3个二维数组,每个二维数组有2个一维数组,每个一维数组有4个数据

  • 相关阅读:
    【HDU2050】折线分割平面
    【Codevs1183】泥泞的道路
    Pair
    【Poj 1832】连环锁
    【Poj1090】Chain
    【UVa 10881】Piotr's Ants
    【Codeforces】665E Beautiful Subarrays
    【T^T】【周赛】第一周周赛——欢迎16级的新同学
    【OI新闻】2016.10.09
    二分图的最大匹配
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5269277.html
Copyright © 2020-2023  润新知