• <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--返回整數(shù)中為1的位數(shù)

            ?原題:

            ? 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 型數(shù)
            ?*? return:
            ?*??? 輸入?yún)?shù) input 的為1的位數(shù)
            ?*? notes:
            ?*??? 計(jì)算 input 中為1的位數(shù)
            ?*? author: A.TNG 2006/06/14 17:00
            ?*/
            int bitCount(short input)
            {
            ??? int n_ret?? = 0;

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

            ??? return n_ret;
            }

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

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

            ??? /* 發(fā)送 PAUSE 命令給系統(tǒng) */
            ??? system("PAUSE");
            }

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

            久久精品综合一区二区三区| 漂亮人妻被中出中文字幕久久| 人妻精品久久无码专区精东影业 | 99久久精品毛片免费播放| 亚洲AV日韩精品久久久久久久| 99久久久国产精品免费无卡顿| 91精品国产高清久久久久久91 | 久久精品国产精品亚洲精品| 久久九九免费高清视频| 欧美大香线蕉线伊人久久| AA级片免费看视频久久| 久久伊人精品一区二区三区| 精品久久久久久国产| 欧美亚洲国产精品久久高清| 亚洲一区中文字幕久久| 亚洲AV无码一区东京热久久| 久久精品18| 亚洲国产精品一区二区久久| 国产aⅴ激情无码久久| 久久久久久无码国产精品中文字幕 | 久久精品国产亚洲网站| 手机看片久久高清国产日韩| 国产精品久久久福利| 精品伊人久久大线蕉色首页| 久久av高潮av无码av喷吹| 久久精品国产亚洲AV无码偷窥| www久久久天天com| 久久久久国产精品熟女影院| 久久九九久精品国产免费直播| 国产精久久一区二区三区| 久久精品国产半推半就| 99久久免费国产特黄| 久久久无码精品亚洲日韩蜜臀浪潮| 欧美一区二区久久精品| 久久久久久毛片免费看| 久久久久久久综合日本| 亚洲精品久久久www| 久久综合久久美利坚合众国| 久久人妻少妇嫩草AV蜜桃| 伊人久久大香线焦AV综合影院| 少妇内射兰兰久久|