[Huawei machine trial exercise questions] 16. Digital statistics, Huawei exercises
Question
Title: for the input integer array, the number of maximum, maximum, minimum, and minimum values in the output array element. Detailed Description: Interface Description prototype: voidOutputMaxAndMin (int * pInputInteger, intInputNum, int * pMaxValue, int * pMaxNum, int * pMinValue, int * pMinNum); input parameter: Int * pInputInteger: integer array pointer Int InputNum: output parameter of the number of array elements (the memory area pointed to by the pointer is valid): int * pMaxValue: Maximum Value in the array int * pMaxNum: Maximum number in the array int * pMinValue: minimum int * pMinNum in the array: Number of minimum values in the array return value: void involves knowledge points: C language basics: array, comparison performance requirements: No lap Complexity Requirements: This is not provided by the problem, the global configuration of the subsequent judgment system is as follows: code projects and use cases such as function circle complexity less than 10 and class public functions less than 20: C/C ++: CPPUNIT use case knowledge of VS2005 Code project embedded project: Use VS2005 project environment Source: software training camp maintainer: d00191780 exercise stage: elementary
Code
/* ------------------------------------- * Date: 2015-06-30 * Author: SJF0115 * Subject: Digital Statistics * Source: Huawei computer ----------------------------------------------- */# include <St. h>/* function: for the input integer array, input: int * pInputInteger: int * InputNum: number of array elements output: int * pMaxValue: Maximum Value in the array int * pMaxNum: Maximum number in the array int * pMinValue: Minimum value in the array int * pMinNum: minimum number in the array returns: void */void OutputMaxAndMin (int * pInputInteger, int InputNum, int * pMaxValue, int * pMaxNum, int * pMinValue, int * pMinNum) {if (pInputInteger = NULL | InputNum <= 0) {return ;}// if * pMaxValue = pInputInteger [0]; * pMinValue = pInputInteger [0]; * pMaxNum = 1; * pMinNum = 1; for (int I = 1; I <InputNum; ++ I) {// update the maximum value if (pInputInteger [I]> * pMaxValue) {* pMaxValue = pInputInteger [I]; * pMaxNum = 1;} // if else if (pInputInteger [I] = * pMaxValue) {++ (* pMaxNum );} // else // update the minimum value if (pInputInteger [I] <* pMinValue) {* pMinValue = pInputInteger [I]; * pMinNum = 1 ;} // if else if (pInputInteger [I] = * pMinValue) {++ (* pMinNum) ;}// else} // for return ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.