C#数组平均数问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1._1
{
class Program
{
static void Main(string[] args)
{
int []arr=new int[10];
for (int i = 0; i < arr.Length; )
{
x: Console.Write("请输入数组arr的第{0}个元素:", i);
string s = Console.ReadLine();
if (s == "")
{
Console.WriteLine("不可输入空串,请重新输入!");
goto x;
}
try
{
int x = Convert.ToInt32(s);
i++;
}
catch
{
Console.WriteLine("你输入的是非法字符,请重新输入");
}
}
Console.WriteLine("数组arry的平均值为:{0}", arr.Average());
Console.ReadLine();
}
}
}
相关推荐
Csharp程序设计-2016(1)-任务29.pdf
Csharp程序设计_2016(1)_任务29.pdf
C#实现输入10个数存入到数组中并求max和min及平均数的方法示例
本文实例讲述了C#实现输入10个数存入到数组中并求max和min及平均数的方法。分享给大家供大家参考,具体如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int nu1, max,min,number; int[] str = new int[10];
1级平均值:1级的总和和平均值
1级平均 第1类的总和与平均值
求平均数的代码c#,我是来拿分而已
c#求平均数的代码,我只是想拿分,我要的是学习,我还没有能力提供自己的东西哇,为什么骗个分那么辛苦啊
计算一个数组的最大值、最小值、总和、平均数和众数
希望这段代码能够帮助你计算数组的最大值、最小值、总和、平均数和众数。如果你有其他问题,请随时提问。在C#中,我们可以使用以下代码来计算一个整型数组的最大值、最小值、总和、平均数和众数。对于计算众数,我们使用了 LINQ 查询和方法链的方式。方法将数组中的每个元素进行分组,然后通过。方法按照分组的数量进行降序排序,最后使用。,其中包含了一些数字。方法选取第一个分组的键值作为众数。方法来计算数组的最大值,使用。方法来计算数组的最小值,使用。方法来计算数组的总和,使用。方法来计算数组的平均数。


