C語言程式 位操作

2021-08-09 21:38:59 字數 1443 閱讀 8492

1.unsigned int reverse_bit(unsigned int value);

這個函式的返回值value的二進位制位模式從左到右翻轉後的值。

如: 在32位機器上25這個值包含下列各位:

00000000000000000000000000011001

翻轉後:(2550136832)

10011000000000000000000000000000

程式結果返回:

2550136832

#include

#include

#include

unsigned

int reverse_bit(unsigned

int value)

else

if ( (value >> i) & 0x01)

}return ret;

}int main()

2.不使用(a+b)/2這種方式,求兩個數的平均值。

#include

#include

int main()

3.程式設計實現:

一組資料中只有乙個數字出現了一次。其他所有數字都是成對出現的。

請找出這個數字。(使用位運算)

#include

#include

#include

int main()

; int i = 0;

int j = 0;

int a = 0;

printf("請輸入4對相同的數字和乙個單獨不同的數字\n");

for (i = 0; i < 9; i++)

for (i = 0; i < 9; i++)

printf("單獨的數字是:%d\n", a);

system("pause");

return

0;}

4.有乙個字元陣列的內容為:」student a am i」,請你將陣列的內容改為」i am a student」.

要求:

不能使用庫函式。只能開闢有限個空間(空間個數和字串的長度無關)。

#include

#include

#include

int main()

; char arr2[14] = ;

for (i = 13; i >= 0; i--)

k = i - 1;

arr2[l++] = ' ';

i--;}}

for(i = 0; i < 14 ;i++)

printf("\n");

system("pause");

return

0;}

c語言之檔案操作程式

題目要求 用 c 語言寫的源程式是一種文字檔案。本專案以 c 語言的源程式為操作物件,完成對源程式的一系列處理,如判斷是否有 main 函式 將某些行加上注釋等。各功能可以分別編制乙個程式實現 建議用這種簡單的方案 也可以編制乙個程式檔案,各功能作為程式中的模組。1 讀入乙個 c 程式,判斷其中是否...

《C語言及程式設計》程式閱讀 檔案操作

返回 賀老師課程教學鏈結 1 閱讀下面的程式,寫出輸出結果,並上機執行程式進行對照 include stdio.h int main fclose infile return 0 include include int main scanf d a fprintf outfile,d a fclos...

C語言程式基礎

1 斐波拉切數列 1,2,3,5,8,13,21 分析 設定變數初值 a 1,b 1 迴圈計算 a a b,b a b 2 將一正整數分解成質因數,例如 輸入90,列印出 90 2 3 3 5 分析 輸入n,對n進行判斷 3 輾轉相除法求最大公約數,最小公倍數,分析 最大公約數 設 a,b tmp ...