C語言中count該怎么用
1 回答

largeQ
TA貢獻2039條經(jīng)驗 獲得超8個贊
1、count在C語言只能說是一個標(biāo)識符,它即不是關(guān)鍵字,也不是具有特殊作用的某個控制符。一般來說,在C語言編程中定義一個count變量或者字面常量用于計數(shù)。比如下面的程序中用count統(tǒng)計一個整數(shù)中二進制表示中二進制位值為1的個數(shù)。
2、例程:
123456789101112131415 | #include<stdio.h> int main() { int i; printf ( "輸入整數(shù):" ); scanf ( "%d" , &i); printf ( "%d" ,i); int count=0; while (i != 0){ count += i&1; i >>= 1; } printf ( "的二進制表示中1的位數(shù)共有%d:\n" , count); return 0; } |
- 1 回答
- 0 關(guān)注
- 5525 瀏覽
添加回答
舉報
0/150
提交
取消