C#控制台程序:输入十个学生的成绩,并输出最高成绩与最低成绩(标出下标)计算平均成绩 - GXUZF.COM - 林澈思的茶
赵帆同学赵帆同学

输入十个学生的成绩,并输出最高成绩与最低成绩(标出下标)并计算平均成绩
运行结果

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int []num = new int [10];
for (int i = 0; i < 10; i++)
{
Console.WriteLine("请输入第" + i + "个学生的成绩:");
string s = Console.ReadLine();
int x = int.Parse(s);
num[i] = x;
}
int max = num[0];
int k = 0;
for (int n = 1; n < 10; n++)
{
if (max < num[n])
k = n;
max = num[k];
}
Console.WriteLine("最高成绩为是{0},下标为{1}",max,k);
int min = num[0];
int q = 0;
for (int a = 1; a < 10; a++) { if (min > num[a])
q = a;
min = num[q];
}
Console.WriteLine("最低成绩为{0},下标为{1}", min,q);
double all = 0;
for (int h = 0; h < 10; h++)
{
all = all+ num[h];
}
double average = all / 10;
Console.WriteLine("平均成绩为{0}",average);
Console.ReadKey(false);
}
}
}

评论卡