C#平均値、最大値、最小値の解について

1540 ワード

/* (        ) 

* * Copyright (c) 2011, * : * : 2012 9 10 * : * : C# , : , 10 , 、 . * */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace No._3 { class Program { static void Main(string[] args) { int sum = 0, max = 0, min = 0; float p; int[] a = new int[10]; int num = 10; Console.Write(" :"); for (int i = 0; i < num; i++) { string str = Console.ReadLine(); int x = int.Parse(str); a[i] = x; } max = a[0]; for (int i = 0; i < num-1; i++) { if (a[i] < a[i+1]) { max = a[i+1]; } } min = a[0]; for (int i = 0; i < num-1; i++) { if (a[i] > a[i+1]) { min = a[i+1]; } } for (int i = 0; i < num; i++) { sum += a[i]; } p = (float)sum / num; Console.WriteLine(" :{0} :{1} : {2}", max, min, p); Console.ReadKey(false); } } }