• <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++

            久久人人爽人人爽人人片AV麻豆| 久久久久久国产a免费观看不卡| 精产国品久久一二三产区区别| 久久人人爽人人爽人人片av麻烦| av国内精品久久久久影院| 99久久伊人精品综合观看| 人妻无码精品久久亚瑟影视| 99久久99久久精品免费看蜜桃| 久久久久噜噜噜亚洲熟女综合| 国产成人精品综合久久久久| 91久久香蕉国产熟女线看| 国产精品中文久久久久久久| 99久久精品费精品国产| 亚洲中文字幕无码久久精品1| 国内精品久久久久国产盗摄| 久久精品国产亚洲AV麻豆网站| 亚洲精品国产自在久久| 久久国产精品免费| 国产91色综合久久免费| 中文精品久久久久人妻不卡| 色欲综合久久躁天天躁| 精品久久久久久无码人妻蜜桃| 久久夜色精品国产噜噜亚洲AV| 久久久精品久久久久影院| 精品无码久久久久久国产| 久久婷婷综合中文字幕| 久久精品国产91久久综合麻豆自制 | 久久精品中文字幕大胸| 精品国产VA久久久久久久冰 | 99久久免费国产精精品| 亚洲日韩中文无码久久| 2021国内精品久久久久久影院| 人妻精品久久久久中文字幕| 青春久久| 久久精品成人欧美大片| 超级97碰碰碰碰久久久久最新 | 国产精品青草久久久久婷婷| 色妞色综合久久夜夜| 亚洲AV无一区二区三区久久| 久久中文字幕人妻丝袜| 欧洲精品久久久av无码电影|