zoukankan      html  css  js  c++  java
  • 问题 B: c#输出最大值、最小值和平均值(B)。

    题目描述

    使用C#编写一个控制台应用。输入若干个正整数存入数组中(输入exit表示输入结束),输出最大值、最小值和平均值

    输入

    输入若干个正整数存入数组中

    输出

    输出最大值、最小值和平均值。 平均值保留两位小数。

    样例输入

    .wrapper {position: relative;} #input {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;}

    1
    2
    3
    4
    5
    6
    7
    8
    9
    exit

    样例输出

    9
    1
    5.00
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace 输出最大值最小值和平均值
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] a = new int[1000];
                int max, min;
                string s;
                double avg = 0,sum = 0;
                // for(int i = 0; i < 10; ++ i)    a[i] = Convert.ToInt32(Console.ReadLine());
                int k = 0;
                while ("exit" != (s = Console.ReadLine()))
                {
                    a[k] = Convert.ToInt32(s);
                    k++;
                }
                max = min = a[0];
                for (int i = 0; i < k; ++i)
                {
                    if (a[i] > max) max = a[i];
                    if (a[i] < min) min = a[i];
                    sum += a[i];
                }
                avg = sum / k;
                Console.WriteLine(max);
                Console.WriteLine(min);
                Console.WriteLine("{0:F2}",avg);
                Console.ReadKey();
            }
        }
    }
    

      

  • 相关阅读:
    纪中第三天
    纪中第一天
    图片验证码的实现
    使用监听器解决路径问题
    log4j测试示例
    redis示例
    kafka示例
    CSRF verification failed. Request aborted.
    TemplateDoesNotExist
    创建 django 项目命令
  • 原文地址:https://www.cnblogs.com/mjn1/p/12523888.html
Copyright © 2011-2022 走看看