计算数组中最大值、最小值和平均值的方法(The methods of calculating the maximum, minimum and average of a array )

计算一个数据的最大值最小值和平均值是很常用的方法,最近因为要用到这些方法,特总结如下,因为较常见,具体的分析方法就不提供了:

/*********************************************Get the maximum of the input values*******************************/
/***************************************************************************************************************/
/*Author: TianLiang                                                                                            */
/*Time: 2011/10/13                                                                                             */
/*Function: Get the maximum value from the given numbers                                                       */

double CCalculateSimilarity::MaxValue(double valueArray[],int nLength)
{
	double valueHeader=valueArray[0];//Get the first value of the array
	for(int i=1;i<nLength;i++)
	{
		valueHeader=(valueHeader < valueArray[i]) ? valueArray[i]:valueHeader;//Get the maximum value of the array

	}
	return valueHeader;
}
/*********************************************Get the minimum of the input values*******************************/
/***************************************************************************************************************/
/*Author: TianLiang                                                                                            */
/*Time: 2011/10/13                                                                                             */
/*Function: Get the mimimum value from the given numbers                                                       */

double CCalculateSimilarity::MinValue(double valueArray[],int nLength)
{
	double valueHeader=valueArray[0];//Get the first value of the array
	for(int i=1;i<nLength;i++)
	{
		valueHeader=(valueHeader > valueArray[i]) ? valueArray[i]:valueHeader;//Get the maximum value of the array

	}
	return valueHeader;
}

/*********************************************Get the average of the input values*******************************/
/***************************************************************************************************************/
/*Author: TianLiang                                                                                            */
/*Time: 2011/10/29                                                                                             */
/*Function: Get the average value from the given numbers                                                       */

double CCalculateSimilarity::AverageValue(double valueArray[],int nLength)
{
	double valueSum=0;
	for(int i=1;i<nLength;i++)
	{
		valueSum += valueArray[i];

	}
	return valueSum/nLength;//Get the maximum value of the array
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值