九七年的板蓝根
2018-10-12 04:26
string[,] chengji = new string[,] { { "景珍", "90" }, { "林慧洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龙玉民", "46" }, { "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" } };
int age = 0, sum = 0;
for (int i = 0; i < chengji.Length; i++)
{
sum +=int.Parse(chengji[i,1]);
}
age = sum / chengji.Length;
Console.Write("平均分是{0},高于平均分的有", age);
for (int i= 0; i< chengji.Length; i++)
{
if (int.Parse(chengji[i,1]) > age)
{
Console.Write(chengji[i,0]+"");
}
}
那个逗号一定要是中文的逗号,系统才会显示成功运行 - -!
string[,] chengji = new string[,] { { "景珍", "90 "}, { "林慧洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龙玉民", "46" }, { "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" } };
int age = 0, sum = 0;
for (int i = 0; i < chengji.Length/2; i++)
{
sum += int.Parse(chengji[i,1]);
}
age = sum / (chengji.Length/2);
Console.WriteLine("平均分是{0},高于平均分的有", age);
for (int i = 0; i < chengji.Length / 2; i++)
{
if (int.Parse(chengji[i, 1]) > age)
{
Console.Write(chengji[i, 0] + "");
}
}
数组越界
string[,] chengji = new string[,] { { "景珍", "90 "}, { "林慧洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龙玉民", "46" }, { "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" } };
int age = 0, sum = 0;
for (int i = 0; i < 8; i++)
{
sum += int.Parse(chengji[i,1]);
}
age = sum / 8;
Console.WriteLine("平均分是{0},高于平均分的有", age);
for (int i = 0; i < 8; i++)
{
if (int.Parse(chengji[i, 1]) > age)
{
Console.Write(chengji[i, 0] + "");
}
}
string[] name = new string[] { "景珍 ", "林惠洋", "成蓉 ", "洪南昌", "龙玉民", "单江开 ", "田武山", "王三明" };
int[] scores = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
int j = 0;
int sum = scores[0], avrg;
for (int i = 1; i < scores.Length; i++)
{
sum += scores[i];
}
avrg = sum / scores.Length;
Console.Write("平均分是{0},", avrg);
Console.WriteLine("高于平均分的有:");
for (int i = 0; i < scores.Length; i++)
{
if (scores[i] > avrg)
{
j = i;
Console.Write(name[j]);
}
}
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]+" "); } }
输出结果对了还报错
using System;
using System.Collections.Generic;
using System.Text;
namespace projAboveAvg
{
class Program
{
static void Main(string[] args)
{
string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };
int sum = 0;
foreach (int x in score)
{
sum += x;
}
int avg = sum / (score.Length);
Console.WriteLine("平均分是{0},高于平均分的有:", avg);
string names = "";
for (int x = 0; x < score.Length;x++)
{
if (score[x] > avg)
{
names = names + name[x] + " ";
}
}
Console.Write(names);
}
}
}
string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };
int index = 0;
int sum = 0;
foreach (int x in score)
{
sum += x;
}
int avg = sum / (score.Length);
Console.WriteLine("平均分数是{0},高于平均分的有:", avg);
string names = "";
for (int x = 0; x < score.Length;x++)
{
if (score[x] > avg)
{
names = names + name[x] + " ";
}
}
Console.Write(names);
string[,] chengji = new string[,] { { "景珍", "90" }, { "林慧洋", "65" }, { "成蓉", "88" }, { "洪南昌", "70" }, { "龙玉民", "46" }, { "单江开", "81" }, { "田武山", "100" }, { "王三明", "68" } };
int age = 0, sum = 0;
for (int i = 0; i < chengji.GetLongLength(0); i++)
{
sum+=int.Parse(chengji[i, 1]);
}
age = sum/(int)chengji.GetLongLength(0);
Console.Write("平均分是{0},高于平均分的有", age);
for (int i = 0; i < chengji.GetLongLength(0); i++)
{
if (int.Parse(chengji[i, 1]) > age)
{
Console.Write(chengji[i, 0] + " ");
}
}
C#开发轻松入门
254118 学习 · 1459 问题
相似问题