• <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 旅途 閱讀(125) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

            亚洲欧美日韩久久精品第一区| 久久人人爽人人爽AV片| 久久久久亚洲精品天堂| 久久777国产线看观看精品| 久久久久综合网久久| 青青草原综合久久大伊人导航| 久久综合久久伊人| 久久人人爽人人爽人人AV| 久久av高潮av无码av喷吹| 精品一二三区久久aaa片| 四虎国产精品免费久久5151| 亚洲国产成人精品久久久国产成人一区二区三区综 | 国产 亚洲 欧美 另类 久久| 久久笫一福利免费导航| 伊人色综合久久| 色欲久久久天天天综合网精品| 97超级碰碰碰碰久久久久| 新狼窝色AV性久久久久久| 日本精品久久久久久久久免费| www.久久99| 久久久久亚洲AV成人片| 日产精品久久久久久久| 久久免费视频6| 久久播电影网| 国产亚洲精久久久久久无码AV| 国产精品久久久久久搜索| 久久久久亚洲av无码专区导航| 国产毛片欧美毛片久久久| 久久国产亚洲精品| 思思久久99热只有频精品66 | 久久精品国产色蜜蜜麻豆| 中文精品99久久国产 | 久久精品卫校国产小美女| 久久国产精品偷99| 精品国产乱码久久久久久浪潮| 99999久久久久久亚洲| 国产精品久久精品| 91精品婷婷国产综合久久| 国产精品99久久久久久宅男| 国产高潮国产高潮久久久91 | 久久精品国产亚洲AV香蕉|