码迷,mamicode.com
首页 > 其他好文 > 详细

三则实例

时间:2018-09-28 22:37:37      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:tle   else   int   line   输出矩阵   list   write   avg   lis   

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();
此为本人初学所写,源对需要的人有帮助,如有问题,望多多指教。

 

三则实例

标签:tle   else   int   line   输出矩阵   list   write   avg   lis   

原文地址:https://www.cnblogs.com/deepsleepinger/p/9721281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!