慕莱坞5295872
2022-12-04 16:42
sing System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
class Program
{
static void Main(string[] args)
{
int[]score=new int[]{90,65,88,70,46,81,100,68};
string[]name=new string[]{"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
int sum=0,avg=0;
for(int i=0,i<score.Length;i++)
{
sum+=score[i];
}
avg=sum/score.Length;
Console.WriteLine("平均分是{0},高于平均分的有:",avg);
for(i=0;i<score.Length;i++)
{
if(score[i]>avg)
Console.WriteLine(name[i]+" ");
}
}
}
}
{
int[] score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
string[] name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int sum = 0, avg = 0;
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.WriteLine(name[i] + " ");
}
}
这样就没问题了
string[] name=new string[8]{"景珍","林惠洋","成蓉","洪南昌","尤玉民","单江开","田武山","王三明"};
int[] score = new int[8]{90,65,88,70,46,81,100,68};
int sum =0,avg=0;
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("{0}"+" ",name[i]);
}
for(int i=0,i<score.Length;i++) // 这句错了,int i=0; 分号不是逗号
Console.WriteLine(name[i]+" "); // 输出要求姓名在同一行上,WriteLine输出一个名字后会换行
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
class Program
{
static void Main(string[] args)
{
int[] score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
string[] name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int sum = 0, avg = 0;
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] + " ");
}
}
}
}
第一行using 少了个u
avg = sum / score.Length 不能这样写,要直接写8
我猜是 平均分是{0}, 这段最后的这个逗号没有用中文逗号
C#开发轻松入门
254118 学习 · 1459 问题
相似问题