• <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:
            ?*??? 計算 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()
            {
            ??? /* 輸入需要計算的整數(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 旅途 閱讀(119) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

            色8激情欧美成人久久综合电| 国产精品一区二区久久不卡| 国产精品伦理久久久久久| 18岁日韩内射颜射午夜久久成人 | 狠狠色综合网站久久久久久久| 99久久国产综合精品五月天喷水| 成人午夜精品久久久久久久小说| 无码任你躁久久久久久老妇| 国产精品99精品久久免费| 久久亚洲2019中文字幕| 亚洲va久久久噜噜噜久久男同 | 国产成人久久精品麻豆一区 | 久久久久亚洲AV综合波多野结衣| 伊人久久成人成综合网222| 国产三级久久久精品麻豆三级| 久久精品无码专区免费| 91精品国产高清久久久久久io| 亚洲性久久久影院| 亚洲欧美日韩精品久久| 日韩人妻无码精品久久久不卡 | 久久精品国产亚洲AV不卡| 99re这里只有精品热久久 | 国内精品伊人久久久久av一坑 | 97精品久久天干天天天按摩| 无码任你躁久久久久久久| 久久91精品国产91久久小草| 久久人与动人物a级毛片| 久久男人中文字幕资源站| 久久91精品国产91久久户| 国产精品久久久久jk制服| 久久精品亚洲中文字幕无码麻豆| 人妻丰满?V无码久久不卡| 国内精品免费久久影院| 国产成人99久久亚洲综合精品| 国产午夜精品久久久久免费视| 久久婷婷成人综合色综合| 无码日韩人妻精品久久蜜桃| 色婷婷久久综合中文久久蜜桃av| 99精品久久精品一区二区| 欧美一区二区三区久久综| 久久精品亚洲精品国产色婷|