您的位置:首页 > 其它

函数数组排序带出最大最小值及平均值

2015-04-14 00:19 190 查看
namespace 函数数组排序带出最大最小值及平均值
{
class Program
{
static void Main(string[] args)
{
int[] b=new int[]{9,1,5,3,7};
int max = 0; //设置两个变量用来接收最低值与最小值。
int min = 0;
int ave = 0; //设变一个变量来接收平均值。
int[]a= new Program().Array(b,out max,out min,out ave);
for (int i = 0; i < b.Length; i++)
{
Console.WriteLine( b[i]);
}
Console.WriteLine("最大值"+max);
Console.WriteLine("最小值"+min);
Console.WriteLine("平均值"+ave);
Console.ReadLine();
}
public int[] Array(int[]a,out int x,out int y,out int ave) //跳出x,y和ave三个变量,返回int[]a变量。
{

int temp = 0;
for (int i = 1; i <= a.Length; i++)
{
for (int j = 1; j <= a.Length-i; j++)
{
if(a[j-1]<a[j])
{
temp = a[j - 1];
a[j - 1] = a[j];
a[j] = temp;
}
}
}
x = a[0]; //最大值
y=a[a.Length-1]; //最小值
int sum = 0;
for (int i = 0; i < a.Length; i++)
{

sum = sum + a[i];
}
ave = sum / (a.Length);
return a;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐