每日博客

C#

编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在该

列上最小。有可能数组没有鞍点)。要求:

u   二维数组的大小、数组元素的值在运行时输入;

u   程序有友好的提示信息。

namespace test

{

    class test_1

{

public void test_1_5()

        {

            while (true)

            {

                Console.WriteLine("请输入二维数组的行数:");

                int row = int.Parse(Console.ReadLine());

                Console.WriteLine("请输入二维数组的列数:");

                int column = int.Parse(Console.ReadLine());

                float[,] a = new float[row, column];       

                Console.WriteLine("请输入二维数组元素:");

                for (int i = 0; i < row; i++)   

                    for (int j = 0; j < column; j++){

                        Console.WriteLine("请输入第{0}个数:", i * row + j + 1);

                        a[i, j] = float.Parse(Console.ReadLine());

                    }

                }

                int count = 0;                            

                for (int i = 0; i < row; i++)           

                {

                    int maxj = 0;                       

                    for (int j = 0; j < column; j++)

                        if (a[i, j] > a[i, maxj])

                            maxj = j;

                    int minx = 0;                     

                    for (int j = 0; j < row; j++)     

                        if (a[j, maxj] < a[minx, maxj])

                            minx = j;

                    if (a[i, maxj] == a[minx, maxj])

                        Console.Write("鞍点[{0},{1}]:{2}" + '\n', minx, maxj, a[minx, maxj]); count++;

                }

                if (count == 0) Console.WriteLine("没有鞍点数");

                else Console.WriteLine("鞍点总数为:" + count);

            }

        }

    }

    class main

    {

        static void Main(string[] args)

        {

            test_1 t = new test_1();

            t.test_1_5();

        }

    }

}

 

posted @ 2021-10-06 21:01  谦寻  阅读(46)  评论(0编辑  收藏  举报