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

            久久精品国产亚洲αv忘忧草| 久久久久亚洲精品天堂久久久久久| 国产精品久久久香蕉| 色欲久久久天天天综合网精品| 日韩精品国产自在久久现线拍| 思思久久精品在热线热| 亚洲国产精品18久久久久久| 精品久久久久久| 久久久久人妻一区精品色| 久久亚洲天堂| 国内精品久久久久久99| 日韩人妻无码精品久久免费一| 中文字幕无码久久久| 久久综合色之久久综合| 久久亚洲私人国产精品vA| 久久精品国产99国产精品| 久久国产乱子伦精品免费午夜| 人妻无码精品久久亚瑟影视| 国产精品丝袜久久久久久不卡| 国产成人AV综合久久| 久久夜色精品国产噜噜麻豆| 久久中文字幕人妻熟av女| 精品久久久久久无码中文字幕 | 久久99精品国产一区二区三区| 久久青青草原精品国产不卡| 久久久久综合网久久| 久久天天躁狠狠躁夜夜96流白浆| 亚洲欧洲久久久精品| 精品99久久aaa一级毛片| 久久电影网一区| 久久国产成人精品麻豆| 国产欧美久久一区二区| 久久99精品久久久久久hb无码| 亚洲色大成网站www久久九| 久久九九精品99国产精品| 中文字幕无码久久人妻| 中文国产成人精品久久亚洲精品AⅤ无码精品| 久久久久一区二区三区| 激情五月综合综合久久69| 久久久久亚洲av成人无码电影 | 伊人精品久久久久7777|