题目描述
使用C#编写一个控制台应用。输入10个正整数存入数组中,输出最大值、最小值和平均值
输入
输入10个正整数
输出
最大值、最小值和平均值
样例输入
1
2
3
4
5
6
7
8
9
10
样例输出
10
1
5.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 输出最大值最小值和平均值
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[10];
int max, min;
double avg = 0,sum = 0;
for(int i = 0; i < 10; ++ i) a[i] = Convert.ToInt32(Console.ReadLine());
max = min = a[0];
for (int i = 0; i < 10; ++i)
{
if (a[i] > max) max = a[i];
if (a[i] < min) min = a[i];
sum += a[i];
}
avg = sum / 10;
Console.WriteLine(max);
Console.WriteLine(min);
Console.WriteLine(avg);
Console.ReadKey();
}
}
}