内容纲要

计算每个同学的平均分,计算全班所有科目额平均分,计算每门科目的平均分

static void Main(string[] args)
        {
            int[,] a = new int[5, 3]
            {
                {1,2,3 },
                {4,5,6 },
                {7,8,9 },
                {10,11,12 },
                {13,14,15 }
            };
            int sum = 0;
            int avg = 0;
            int G_avg = 0;
            for (int row = 0; row < a.GetLength(0); row++) 
            {
                for (int col = 0; col < a.GetLength(1); col++) 
                {
                    avg += a[row, col];
                    sum += a[row, col];
                    Console.Write("{0}\t", (a[row, col]));
                }

                Console.WriteLine("第{0}位同学平均分为:{1}",row+1, avg / 3);
                avg = 0;
            }
            Console.WriteLine("总平均分为:{0}", sum / 5);
            Console.WriteLine();
            for (int row = 0; row < a.GetLength(1); row++)
            {
                for (int col = 0; col < a.GetLength(0); col++)
                {
                    G_avg += a[col,row];
                    //Console.Write("{0}\t", (a[row, col]));
                }

                Console.WriteLine("第{0}门课的平均分为:{1}",row+1 ,G_avg / 5);
                G_avg = 0;
            }
        }

发表评论