慕莱坞0209110
2021-01-09 15:04
using System;
using System.Collections.Generic;
using System.Text;
namespacehttps://www.imooc.com/code/9177#editor-tabs-csharp projGetMaxScore
{
class Program
{
static void Main(string[] args)
{
int i; int t=0;
string [] name=new string[]{"吴松","钱东宇","伏晨","陈陆","周蕊","林日鹏","何昆","关欣"};
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("分数最高的是{0},"+"分数是{1}",name[t],score[t]);
}
}
}
string[] name=new string[] {"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
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]+" ");
}
}
这题第一个循环先求和,然后算出平均数,第二个循环将每个人的分数与平均数比较,若大于平均数,则输出姓名加空格 ,比如 name+" "
C#开发轻松入门
254118 学习 · 1459 问题
相似问题