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.
精彩评论