[華為機試練習題]16.數字統計,華為練習題

來源:互聯網
上載者:User

[華為機試練習題]16.數字統計,華為練習題

題目

題目標題:對輸入的整型數組,輸出數組元素中的最大值、最大值的個數、最小值和最小值的個數詳細描述:介面說明原型:voidOutputMaxAndMin(int * pInputInteger,intInputNum,int * pMaxValue,int * pMaxNum,int * pMinValue,int * pMinNum);輸入參數:    Int * pInputInteger:整型數組指標Int   InputNum:數組元素個數輸出參數(指標指向的記憶體地區保證有效):    int* pMaxValue:數組中最大值     int* pMaxNum:數組中最大值的個數     int* pMinValue:數組中最小值int* pMinNum:數組中最小值的個數傳回值:    void涉及知識點:C語言基礎:數組、比較效能要求:無循環複雜度要求:這個不由出題者提供,由後續判題系統全域配置如:函數循環複雜度低於10,類公函數小於20等代碼工程和用例:C/C++:VS2005代碼工程嵌入工程的CPPUNIT用例知識點:     工程環境請使用VS2005題目來源:    軟體訓練營 維護人:     d00191780 練習階段:    初級 

代碼

/*---------------------------------------*   日期:2015-06-30*   作者:SJF0115*   題目:數字統計*   來源:華為上機-----------------------------------------*/#include <stdio.h>/*功能:對輸入的整型數組,輸出數組元素中的最大值、最大值的個數、最小值和最小值的個數輸入:int * pInputInteger:整型數組指標     int * InputNum:數組元素個數輸出:int * pMaxValue:數組中最大值     int * pMaxNum:數組中最大值的個數     int * pMinValue:數組中最小值     int * pMinNum:數組中最小值的個數返回: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){        // 更新最大值        if(pInputInteger[i] > *pMaxValue){            *pMaxValue = pInputInteger[i];            *pMaxNum = 1;        }//if        else if(pInputInteger[i] == *pMaxValue){            ++(*pMaxNum);        }//else        // 更新最小值        if(pInputInteger[i] < *pMinValue){            *pMinValue = pInputInteger[i];            *pMinNum = 1;        }//if        else if(pInputInteger[i] == *pMinValue){            ++(*pMinNum);        }//else    }//for    return;}

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.