二维数组练习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建一个二维数组,数组内容是某3位同学的各自5门课程所有成绩
            //即学生是一个三行四列二维数组
            int[,] score1 = new int[3, 5]
            { 
            { 78, 98, 75, 89,78 },
            { 45, 65, 78, 99 ,89}, 
            { 78, 56, 86, 78 ,69}
            };
            //把所有同学的成绩全部输出
            Console.WriteLine("----------学生的全部成绩-------------");
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Console.Write(score1[i, j] + " ");
                }
                Console.WriteLine();
            }
            //修改第一名同学的最后一门课程成绩
            Console.WriteLine("----------第一名同学修改后的成绩-------------");
            score1[0, 4] = 97;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Console.Write(score1[i, j] + " ");
                }
                Console.WriteLine();
            }
            //修改最后一名同学的第一门课程成绩
            Console.WriteLine("----------最后一名同学修改后的成绩-------------");
            score1[2, 0] = 85;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Console.Write(score1[i, j] + " ");
                }
                Console.WriteLine();
            }
            //输出所有同学的平均分,即每行所对应的成绩平均分
            Console.WriteLine();
            for (int i = 0; i < 3; i++)
            {
                int sum = 0;
                Console.Write("第{0}个学生的平均成绩是:", i + 1);
                for (int j = 0; j <= 4; j++)
                    sum += score1[i, j] / 5;
                Console.WriteLine(sum);
            }
            //输出班级各科平均分,既每列的平均分
            Console.WriteLine();
            for (int i = 0; i < 3; i++)
            {
                int sum1 = 0;
                Console.Write("第{0}个学生的各科平均成绩是:", i + 1);
                for (int j = 0; j < 5; j++)
                    sum1 += score1[i, j];
                Console.WriteLine(sum1 / 5);
            }

            // 找出3名同学最后一门课程的最高分,既是最后一列中的最大值


            Console.WriteLine("------------最后一门课程的最高分-------------");
            int max1 = score1[0, 4];
            for (int j = 1; j < 3; j++)
            {
                if (score1[j, 4] > max1)
                    max1 = score1[j, 4];
            }
            Console.WriteLine("最后一门课程的最高分是:" + max1);

            //求出所有同学所有课程的最高分,即每行的最大值
            Console.WriteLine();
            for (int i = 0; i < 3; i++)
            {
                int max = score1[i, 0];
                for (int j = 1; j <= 3; j++)
                {
                    if (score1[i, j] > max)
                        max = score1[i, j];
                }
                Console.WriteLine("第{0}个学生的最高分是{1}", i + 1, max);
            }

            Console.ReadKey();

        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值