三则实例

Posted deepsleepinger

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三则实例相关的知识,希望对你有一定的参考价值。

1、三名参赛者,10名考官,每个参赛者的成绩是10名考官给出的成绩去掉最高分和去掉最低分而求出的平均分,输出每名参赛者最后得分。

int[,] list = new int[3, 10];
            for (int i = 0; i < list.GetLength(0); i++)
            {
                int sum = 0, max = 0, min = 0;
                float avg = 0;
                for (int j = 0; j < list.GetLength(1); j++)
                {
                    Console.WriteLine("请输入第{0}名选手中第{1}位评委的成绩:", i + 1, j + 1);
                    int request = int.Parse(Console.ReadLine());
                    sum = sum + request;
                    if (request > max)
                        max = request;
                    if (request < min)
                        min = request;
                }
                avg = (sum - min - max) / 8;
                Console.WriteLine("第{0}名学生的成绩为:{1}", i + 1, avg);
            }
            Console.ReadLine();

2、 使用二维数组,存储一个矩阵,转置矩阵,输出矩阵

static void Main(string[] args)
        {
           
            int[,] a = new int[2, 3] { { 1, 2, 3, }, { 4, 5, 6 } };
            int[,] b = new int[,] { };
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    b[i, j] = a[j, i];
                }
            }
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine(a[i,1]);
            }
                Console.Read();
        }

3、 统计5*6数组中奇数和偶数的个数

int ss = 0, ds = 0;
            int[,] list = { { 1, 2, 9, 4, 5, 6 },
                            { 1, 2, 3, 3, 5, 6 },
                            { 2, 6, 9, 8, 6, 7 },
                            { 8, 2, 3, 4, 5, 8 },
                            { 8, 2, 4, 8, 4, 6 } };
            for (int i = 0; i < list.GetLength(0); i++)
            {
                for (int j = 0; j < list.GetLength(1); j++)
                {
                    int num = list[i, j];
                    if (num % 2 == 0)
                        ss++;
                    else
                        ds++;
                }
            }
            Console.WriteLine("奇数为:{0}个,偶数为{1}个。",ss,ds);
            Console.Read();
此为本人初学所写,源对需要的人有帮助,如有问题,望多多指教。

 





















































以上是关于三则实例的主要内容,如果未能解决你的问题,请参考以下文章

GitHub小技巧三则

lua语言三则特性

使用kubeadm安装k8s集群故障处理三则

18.03.03 位运算作业三则

UEStudio使用技巧三则

18.11.13 二叉树三则