為什么結(jié)果就是不對
int[] fs= new int[4];
? ? ? ? ? ? string[] name = new string[4];
? ? ? ? ? ? int max = fs[0];
? ? ? ? ? ? string maxname=null;
? ? ? ? ? ? for (int i=0;i<name.Length;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("請輸入第" +(i+1) + "位學(xué)生的姓名");
? ? ? ? ? ? ? ? name[i]=Console.ReadLine();
? ? ? ? ? ? ? ? Console.WriteLine("請輸入第" +(i+1) + "位學(xué)生的成績");
? ? ? ? ? ? ? ? fs[i]=int.Parse(Console.ReadLine());
? ? ? ? ? ? ? ? if (fs[i] > max)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = fs[i];
? ? ? ? ? ? ? ? ? ? maxname = name[i];
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("最大值是:" + max + "人是" + maxname);
? ? ? ? ? ??
? ? ? ??
? ? ? ? ? ? int sum = 0, avg=0;?
? ? ? ? ? ? for(int j=0;j<fs.Length;j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum = sum + fs[j];
? ? ? ? ? ? ? ? avg = sum / fs.Length;
? ? ? ? ? ? ? ? if (fs[j]>avg)
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? Console.WriteLine( name[j]);
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
2019-03-02
? ? ? ? ? ? int[] fs = new int[4];
??????????? string[] name = new string[4];
??????????? int max = fs[0];
??????????? string maxname = null;
??????????? int sum = 0;
??????????? for (int i = 0; i < name.Length; i++)
??????????? {
??????????????? Console.WriteLine("請輸入第" + (i + 1) + "位學(xué)生的姓名");
??????????????? name[i] = Console.ReadLine();
??????????????? Console.WriteLine("請輸入第" + (i + 1) + "位學(xué)生的成績");
??????????????? fs[i] = int.Parse(Console.ReadLine());
??????????????? if (fs[i] > max)
??????????????? {
??????????????????? max = fs[i];
??????????????????? maxname = name[i];
??????????????? }
??????????????? sum = sum + fs[i];
??????????? }
??????????? Console.WriteLine("最大值是:" + max + "人是" + maxname);
??????????? int avg;
??????????? avg = sum / fs.Length;
??????????? Console.WriteLine("平均分是{0},高于平均分的有",avg);
??????????? for (int j = 0; j < fs.Length; j++)
??????????? {
??????????????? if (fs[j] > avg)
??????????????? {
??????????????????? Console.WriteLine(name[j]+" ");
??????????????? }
??????????? }
//sum要放在第一個循環(huán)里,avg放在循環(huán)的外面,不然就是sum的第一個總值被除,而不是全部被除。
2018-09-20
再縷縷思路