• 课堂题目54


    课堂题目5-4

    课程元素类型 任务

    输入某班10名同学语文、数学、英语期末考试成绩,输出各门课程平均成绩。

    总结:二维数组开端

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace _5_4
    {
        class Program
        {
            static void Main(string[] args)
            {
                double[,] dA = new double[3, 3]; //存放成绩数组
                string[] szA = new string[] { "语文", "数学", "英语" }; //课程名
                double[] dB = new double[3];//存放平均成绩
                double dC;//临时统计
    
                dC = 0.0;
    
    
    
                //*
                //
                //*         输入成绩并保存到数组
                //
                //*
    
    
                for (int i = 0; i < dA.GetLength(0); i++)
                {
                    for (int j = 0; j < dA.GetLength(1); j++)
                    {
                        Console.Write("请输入第{0}个同学的{1}成绩:", j + 1, szA[i]);
                        dA[i, j] = Convert.ToDouble(Console.ReadLine());
    
                    }
                    Console.WriteLine("{0}成绩统计完毕!",szA[i]);
                }
                Console.WriteLine("--------------------------");
                //*
                //
                //*         统计每门课的平均成绩
                //
                //*
                Console.WriteLine("每门课的班级平均成绩为:");
                for (int i = 0; i < dA.GetLength(0); i++)
                {
                    for (int j = 0; j < dA.GetLength(1); j++)
                    {
    
                        dC = dC + dA[i, j];
                    }
                    Console.WriteLine("{0}的平均成绩为{1}", szA[i], dC / dA.GetLength(1));
                    dC = 0.0;
                }
                Console.WriteLine("--------------------------");
                //*
                //
                //*         统计同学的平均成绩
                //
                //*
                for (int i = 0; i < dA.GetLength(1); i++)
                {
                    for (int j = 0; j < dA.GetLength(0); j++)
                    {
    
                        dC = dC + dA[j, i];
                    }
                    Console.WriteLine("第{0}同学的平均成绩为{1}", i+1,dC / dA.GetLength(0));
                    dC = 0.0;
                }
                Console.WriteLine("--------------------------");
                Console.ReadKey(true);
    
            }
        }
    }
  • 相关阅读:
    关于本站点(说明)
    对Python的认识以及以及Python变量简单的数据类型总结
    分享一个Ubuntu16.0.4安装MySQL5.7脚本
    Shell编程之批量安装服务脚本实例剖析
    Shell编程之批量安装服务脚本实例
    Shell编程之while&until循环详解
    Shell编程之case语句实战
    Shell编程之函数用法 (详解)
    Shell编程之if语句实战(详解)
    mongodb 查询语句笔记
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2792176.html
Copyright © 2020-2023  润新知