僅僅提供參考
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[] a =new string[8]{
? ? ? ? ? ? ? ? "景珍","林惠洋","成蓉","洪南昌","龍玉民","單江開","田武山","王三明"
? ? ? ? ? ? };
? ? ? ? ? ? int[] b = new int[8]{
? ? ? ? ? ? ? ? 90,65,88,70,46,81,100,68
? ? ? ? ? ? };
? ? ? ? ? ? int c = 0;
? ? ? ? ? ? foreach(var x in b){
? ? ? ? ? ? ? ? c += x;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("平均分是{0},高于平均分的有:",c/8);
? ? ? ? ? ? for(var i=0;i<b.Length;i++){
? ? ? ? ? ? ? ? if(b[i]>c/8){
? ? ? ? ? ? ? ? ? ? Console.Write(a[i]+" ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
2018-09-12
?string[] name = new string[8] { "景珍", "林惠洋", "成蓉", "洪南昌", "龍玉民", "單江開", "田武山", "王三明" };
??????????? int[] score = new int[8] { 90,65,88,70,46,81,100,68 };
??????????? int sum = 0, avg;
??????????? int e = 0;
??????????? for (int i = 0; i < score.Length; i++)
??????????? {
??????????????? sum += score[i];
??????????? }
??????????? avg = sum / score.Length;
??????????? Console.Write("平均分是" + avg);
??????????? Console.WriteLine(",高于平均分的有:");
??????????? for (int j=0;j<score.Length;j++)
??????????? {
??????????????? if (score[j] > avg)
??????????????? {
??????????????????? e = j;
??????????????????? Console.Write(name[e]+" ");
??????????????? }?
??????????? }