zoukankan      html  css  js  c++  java
  • 课堂题目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);
    
            }
        }
    }
  • 相关阅读:
    不可或缺 Windows Native (15)
    不可或缺 Windows Native (14)
    不可或缺 Windows Native (13)
    不可或缺 Windows Native (12)
    不可或缺 Windows Native (11)
    不可或缺 Windows Native (10)
    不可或缺 Windows Native (9)
    不可或缺 Windows Native (8)
    不可或缺 Windows Native (7)
    不可或缺 Windows Native (6)
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2792176.html
Copyright © 2011-2022 走看看