开发者

enter array input n solve some question with method

i need to know how to do array. but, we insert the input and no user input. when complete the table, we must show the average, maximum score, minimum开发者_如何转开发 score and identify which the table has maximum or minimum score using the method.. can help me?


Linq offers extension methods:

arr.Max()
arr.Min()
arr.Average()

Or manually:

int maxIndex=0;
int minIndex=0;
double sum=0;
double min=arr[0];
double max=arr[0];

for(int i=0;i<arr.Length;i++)
{
  sum+=arr[i];
  if(arr[i]>max)
  {
    max=arr[i];
    maxIndex=i;
  }
  if(arr[i]<min)
  {
    min=arr[i];
    minIndex=i;
  }
}
double average=sum/arr.Length;

Note: The behavior in the presence of NaNs might not be as you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜