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

            亚洲国产日韩欧美久久| 无码伊人66久久大杳蕉网站谷歌 | 久久97久久97精品免视看 | 久久只有这精品99| 中文字幕乱码人妻无码久久| 精品久久一区二区| 性做久久久久久久久浪潮| 人妻精品久久无码专区精东影业| 成人国内精品久久久久影院VR| 久久一本综合| 久久99国产精品久久99果冻传媒| 久久青青国产| 久久久精品午夜免费不卡| 久久精品桃花综合| 久久99精品久久久久久齐齐| 香蕉久久夜色精品升级完成 | MM131亚洲国产美女久久| 日韩美女18网站久久精品| 国产成年无码久久久久毛片| 久久亚洲AV无码精品色午夜 | 国产精品久久久久久影院| 亚洲欧洲精品成人久久曰影片| 91久久精品国产91性色也| 色综合久久无码五十路人妻| 欧美精品九九99久久在观看| 办公室久久精品| 88久久精品无码一区二区毛片 | 伊人情人综合成人久久网小说| 国产精品美女久久久免费| 国产精品一区二区久久国产| 亚洲国产精品久久久天堂| 久久精品成人欧美大片| 久久久久国产| 一级做a爰片久久毛片免费陪| 久久人搡人人玩人妻精品首页| 久久精品亚洲福利| 久久亚洲天堂| 18禁黄久久久AAA片| 久久精品国产AV一区二区三区| 无码人妻久久久一区二区三区| 欧美日韩精品久久免费|