Title Description
Use a console application written in C #. A plurality of input into positive integer array (represented type exit end of input), the output of the maximum, minimum and average
Entry
Enter the number of positive integers into an array
Export
Output maximum, minimum and average. The average of two decimal places.
Sample input
.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
Sample Output
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(); } } }