zoukankan      html  css  js  c++  java
  • c#笔记(六)——数组(2)

    //将一个二维数组的行和列交换,存储到另外一个数组中
                //int[,] a = new int[2, 3] { { 1, 2 ,3},{ 4, 5, 6 } };
               // int[,] b = new int[a.GetLength(1), a.GetLength(0)];
               // for (int i = 0; i < b.GetLength(0); i++)
               // {
               //     for (int j = 0; j < b.GetLength(1); j++)
               //     {
               //         b[i, j] = a[j, i];
               //         Console.Write(b[i,j]+" ");
               //     }
               //     Console.WriteLine();
               //}
    //有个3行4列的二维数组,求最大元素以及所在的行和列
                //int[,] a = new int[3, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
                //int max, row, line;
                //max = a[0,0];
                //row = 0;
                //line = 0;
                //for (int i = 0; i < a.GetLength(0); i++)
                //{
                //    for (int j = 0; j < a.GetLength(1); j++)
                //    {
                //        if (max < a[i, j])
                //        {
                //            max = a[i, j];
                //            row = i;
                //            line = j;
                //        }
                //    }
                //}
                //Console.WriteLine("max={0},行号是{1},列号是{2}", max, row+1, line+1);
               赋值一个二维数组
    //int[,] a = new int[4, 3];
                //for (int i = 0; i < a.GetLength(0); i++)
                //{
                //    Console.WriteLine("请输入第{0}行赋值的数",i);
                //    for (int j = 0; j < a.GetLength(1); j++)
                //    {
                //        a[i, j] = int.Parse(Console.ReadLine());
                //    }
     
                //}
                //Console.ReadKey();
                ////打印数组
                //Console.WriteLine("打印赋值的数组");
                //for (int i = 0; i < a.GetLength(0); i++)
                //{
                //    for (int j = 0; j < a.GetLength(1); j++)
                //    {
                //        Console.Write(a[i, j] + " ");
                //    }
                //    Console.WriteLine();
                //}
     
                //Console.WriteLine("第一行元素");
                //for (int i = 0; i < a.GetLength(1); i++)
                //{
                //    Console.Write(a[0, i] + " ");
                //}
                //Console.WriteLine("和");
                //int sum = 0;
                //for (int i = 0; i < a.GetLength(1); i++)
                //{
                //    sum += a[1, i];
                //}
                //Console.WriteLine("sum=" + sum);
  • 相关阅读:
    第十章、数据库运行维护与优化
    第九章、安全管理
    第八章、数据库后台编程技术
    第七章、高级数据库查询
    第六章、数据库及数据库对象
    第五章、UML与数据库应用系统
    第四章、数据库应用系统功能设计与实施
    struts2标签debug
    SSH框架 more than one namespace has been specificed without a prefix
    Http Status 404
  • 原文地址:https://www.cnblogs.com/ningyongbin/p/5922151.html
Copyright © 2011-2022 走看看