幫忙看看謝謝
using System;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };
? ? ? ? ? ? string[] name = { "景珍", "林慧洋", "成蓉", "洪南昌", "龍玉民", "單江開", "田武山", "王三明" };
? ? ? ? ? ? double sum = 0;
? ? ? ? ? ? double avg;
? ? ? ? ? ? for (int i = 0; i < score.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? double avg2;
? ? ? ? ? ? ? ? sum += score[i];
? ? ? ? ? ? ? ? //Console.WriteLine(sum);//
? ? ? ? ? ? ? ? avg2 = sum / 8;
? ? ? ? ? ? ? ? if (score[i] > avg2)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("當(dāng)前高于平均分的有" + name[i]);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? avg = sum / 8;
? ? ? ? ? ? Console.Write("平均分為" + avg);
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
? ? }
2020-11-23
? ? ? ? ? ?// 創(chuàng)建姓名數(shù)組,存儲8位同學(xué)的姓名
? ? ? ? ? ? string[] names = new string[]{"景珍","林惠洋","成蓉","洪南昌","龍玉民","單江開","田武山","王三明"};
? ? ? ? ? ? // 創(chuàng)建分?jǐn)?shù)數(shù)組,存儲9位同學(xué)的分?jǐn)?shù)
? ? ? ? ? ? int[] scores = new int[]{90,65,88,70,46,81,100,68};
? ? ? ? ? ? // 循環(huán)數(shù)組,累加總分
? ? ? ? ? ? int sum = 0;? // 記錄總分
? ? ? ? ? ? for(int i = 0; i < scores.Length; i++){
? ? ? ? ? ? ? ? sum += scores[i];
? ? ? ? ? ? }
? ? ? ? ? ? // 計(jì)算平均分
? ? ? ? ? ? int avg = sum / scores.Length;
? ? ? ? ? ? Console.WriteLine("平均分是{0},高于平均分的有:", avg);
? ? ? ??
? ? ? ? ? ? // 循環(huán)每一位同學(xué)的分?jǐn)?shù),并在其內(nèi)判斷每一位同學(xué)的分?jǐn)?shù)是否大于平均分,如果大于則打印出這位同學(xué)的姓名
? ? ? ? ? ? for(int i = 0; i < scores.Length; i++){
? ? ? ? ? ? ? ? if(scores[i] > avg){
? ? ? ? ? ? ? ? ? ?Console.Write(names[i] + " ");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
2020-10-23
int[] score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
??????????? string[] name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龍玉民", "單江開", "田武山", "王三明" };
??????????? int sum = 0, ave;
??????????? for (int i = 0; i < score.Length; i++)
??????????? {
??????????????? sum += score[i];
??????????? }
??????????? ave = sum / score.Length;
??????????? Console.WriteLine("平均分是{0},高于平均分的有:", ave);//特別注意這里的{0}后面的逗號是中文的逗
//號后面有空格, 冒號也是中文下的??!
??????????? for (int k = 0; k < score.Length; k++)
??????????? {
??????????????? if (score[k] > ave)
??????????????? {
??????????????????? Console.Write(name[k]+" ");
??????????????? }
??????????? }