測(cè)出的結(jié)果
using System;
using System.Collections.Generic;
using System.Text;
namespacehttp://idcbgp.cn/code/9177#editor-tabs-csharp projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int i; int t=0;
? ? ? ? ? ? string [] name=new string[]{"吳松","錢(qián)東宇","伏晨","陳陸","周蕊","林日鵬","何昆","關(guān)欣"};
? ? ? ? ? ? int [] score=new int[]{89,90,98,56,60,91,93,85};
? ? ? ? ? ? for(i=0;i<score.Length;i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(score[i]>score[t])
? ? ? ? ? ? ? ? t=i;
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("分?jǐn)?shù)最高的是{0},"+"分?jǐn)?shù)是{1}",name[t],score[t]);
? ? ? ? }
? ? }
}
2021-02-05
string[] name=new string[] {"景珍","林惠洋","成蓉","洪南昌","龍玉民","單江開(kāi)","田武山","王三明"};
? ? ? ? ? ?int [] score=new int[] {90,65,88,70,46,81,100,68};
? ? ? ? ? ?int sum=0,avg;
? ? ? ? ? ?for(int i=0;i<score.Length;i++){
? ? ? ? ? ? ? ?sum+=score[i];
? ? ? ? ? ?}
? ? ? ? ? ?avg=sum/score.Length;
? ? ? ? ? ?Console.WriteLine("平均分是{0},高于平均分的有:",avg);
? ? ? ? ? ?for(int i=0;i<score.Length;i++){
? ? ? ? ? ? ? ?if(score[i]>avg){
? ? ? ? ? ? ? ? ? ?Console.Write(name[i]+" ");
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
這題第一個(gè)循環(huán)先求和,然后算出平均數(shù),第二個(gè)循環(huán)將每個(gè)人的分?jǐn)?shù)與平均數(shù)比較,若大于平均數(shù),則輸出姓名加空格 ,比如? ? ?name+" "