• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            旅途

            如果想飛得高,就該把地平線忘掉

            面試系列1--返回整數中為1的位數

            ?原題:

            ? Write the function int bitCount(short input) that takes a short as input and
            ? returns an int.? The function returns the number of bits set in the input
            ? variable.? For instance:
            ? bitCount(7) --> 3
            ? bitCount(2543) --> 9
            ? bitCount(11111) --> 9

            代碼:

            /********************************************************************
            ??? created:??? 2006/06/14
            ??? created:??? 14:6:2006?? 16:53
            ??? filename:?? C:\Documents and Settings\Administrator\My Documents\近期閱讀\myTinyThing\bitCount.c
            ??? file path:? C:\Documents and Settings\Administrator\My Documents\近期閱讀\myTinyThing
            ??? file base:? bitCount
            ??? file ext:?? c
            ??? author:???? A.TNG
            ??? version:??? 0.0.1
            ???
            ??? purpose:??? 面試題
            ??????????????? Write the function int bitCount(short input) that takes a short as input and
            ??????????????? returns an int.? The function returns the number of bits set in the input
            ??????????????? variable.? For instance:
            ??????????????? bitCount(7) --> 3
            ??????????????? bitCount(2543) --> 9
            ??????????????? bitCount(11111) --> 9
            *********************************************************************/
            #include <stdio.h>

            /*
            ?*? name: bitCount
            ?*? params:
            ?*??? input???????? [in]??????? 需要分析的 short 型數
            ?*? return:
            ?*??? 輸入參數 input 的為1的位數
            ?*? notes:
            ?*??? 計算 input 中為1的位數
            ?*? author: A.TNG 2006/06/14 17:00
            ?*/
            int bitCount(short input)
            {
            ??? int n_ret?? = 0;

            ??? /* 只要 input 不為0,則循環判斷 */
            ??? while (0 != input)
            ??? {
            ??????? /* 如果 input & 1 == 1 則表示最低位為1,反之則等于0 */
            ??????? if (input & 1)
            ??????? {
            ??????????? n_ret++;
            ??????? }
            ??????? input = input >> 1;
            ??? }

            ??? return n_ret;
            }

            /*
            ?*? name: main
            ?*? params:
            ?*??? none
            ?*? return:
            ?*??? 函數返回狀態給系統
            ?*? notes:
            ?*??? 系統 main 函數
            ?*? author: A.TNG 2006/06/14 17:04
            ?*/
            int main()
            {
            ??? /* 輸入需要計算的整數 */
            ??? int n?? = 2543;

            ??? /* 輸出 bitCount 的結果 */
            ??? printf("%d\n", bitCount((short) n));

            ??? /* 發送 PAUSE 命令給系統 */
            ??? system("PAUSE");
            }

            posted on 2007-09-05 01:14 旅途 閱讀(122) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

            99久久伊人精品综合观看| 久久久亚洲AV波多野结衣| 久久se精品一区二区| 日韩精品国产自在久久现线拍| 久久国产综合精品五月天| 亚洲精品第一综合99久久| 久久精品国产清高在天天线| 韩国三级中文字幕hd久久精品| 久久久久久久91精品免费观看| 精品久久一区二区| 伊人久久久AV老熟妇色| 久久综合丝袜日本网| 国产成人无码精品久久久性色| 91亚洲国产成人久久精品| 久久丫忘忧草产品| 国产成人无码精品久久久免费 | 精品免费久久久久久久| 国产视频久久| 国内精品久久久久影院日本 | 精品久久久久久亚洲| 久久精品国产亚洲AV香蕉| 18岁日韩内射颜射午夜久久成人| 久久久www免费人成精品| 久久综合狠狠综合久久97色| 精品久久香蕉国产线看观看亚洲| 精品国产乱码久久久久久呢 | 国产高清美女一级a毛片久久w| 国产激情久久久久久熟女老人| 四虎影视久久久免费观看| 久久av免费天堂小草播放| 久久久中文字幕| 久久99国产精品久久| 国产精品视频久久| 久久精品国产亚洲77777| 精品永久久福利一区二区| 久久天天躁狠狠躁夜夜躁2O2O| 久久久国产精华液| 久久综合给合久久狠狠狠97色| 伊人久久久AV老熟妇色| 久久久老熟女一区二区三区| 久久精品国产亚洲av水果派 |