1樓:匿名使用者
參考上面的進位制轉換演算法。其中八進位制也可以直接輸出,
用printf("%o"),16進位制的,用printf("%x")輸出。
請用c語言編寫一個程式,列印一個與十進位制數(從1到256) 相等的二進位制數,八進位制數和十六進位制數表 100
2樓:匿名使用者
八進位制和十六進位制
可以直接用%o和%x輸出。
二進位制這裡自己弄了下。
#include
int main(int argc, char *argv);for(i = 1; i <= 255; i++)printf("%9s", two);
/*八進位制*/
printf("%4o", i);
/*十六進位制*/
printf("%3x\n", i);
}return 0;}
3樓:太陽當空燥
最簡單的用if語句慢慢套,用手機寫確實有點不想寫
編寫一個程式,列印整數1~156的二進位制,八進位制,十六進位制和十進位制
4樓:匿名使用者
#include
#include
void main()}
5樓:匿名使用者
我說下二進位制的不停的%2 取餘 然後/2得到二進位制數你正常怎麼算二進位制的 現在還怎麼算
編寫程式,利用sub過程把任意一個十進位制整數n分別轉化為二進位制,八進位制,十六進位制數。
6樓:匿名使用者
private sub text1_change()
dim n
if len(text1) > 0 and isnumeric(text1) then
n = val(text1)
dec_to_bin n
dec_to_oct n
dec_to_hex n
else
text1 = ""
end if
end sub
sub dec_to_bin(byval dec)
label5.caption = ""
do while dec > 0
label5.caption = dec mod 2 & label5.caption
dec = dec \ 2
loop
end sub
sub dec_to_oct(byval dec)
label6.caption = ""
do while dec > 0
label6.caption = dec mod 8 & label6.caption
dec = dec \ 8
loop
end sub
sub dec_to_hex(byval dec)
dim a as string
label7.caption = ""
do while dec > 0
a = cstr(dec mod 16)
select case a
case "10": a = "a"
case "11": a = "b"
case "12": a = "c"
case "13": a = "d"
case "14": a = "e"
case "15": a = "f"
end select
label7.caption = a & label7.caption
dec = dec \ 16
loop
end sub
編寫一個vc++程式把十進位制數轉化成二進位制,八進位制,十六進位制。
7樓:匿名使用者
#include
#include
#include
void trans(long m,int base,char *a); // 函式宣告
int _tmain(int argc, _tchar* argv)//只是16進位制的轉換
void trans(long m,int base,char *a)
*p='\0';}
8樓:匿名使用者
#include "iostream.h"
void f1(double p,int q) //編輯對實數p的整數部分進位制轉換的子函式
for(i=t-1;i>=0;i--) //倒序輸出各個模值(m)
cout<
9樓:匿名使用者
這是以前寫的一個十進位制轉換二進位制,八進位制,十六進位制輸出的.在vc6中測試通過. 你參考下. #include /*輸出*/
void print(int i,char *s)printf("\n");
}/*十進位制轉換八進位制*/
void tentoe(int n)
printf("八進位制:");
print(i,str);
}/*十進位制轉換十六進位制*/
void tentohex(int n)
else
str[i]=n%16+'0';
n/=16;
i++;
}printf("十六進位制:");
print(i,str);
}/*十進位制轉換二進位制*/
void tentob(int n)
printf("二進位制:");
print(i,str);
}void main()
10樓:匿名使用者
我學的也是c++ 給你個簡
單的進位制轉換的程式#include
void look(int x)
}void main()}
使用者輸入一個十進位制正整數,然後分別轉換成為二進位制數、八進位制數和十六進位制數輸出。(是c++,不是c)
11樓:匿名使用者
#include
using namespace std;
int main()
cout<十六進位制使用格式化輸出即可,oct表示八進位制,hex表示十六進位制
cout<
cout<
}如果有不懂請追問。
12樓:支景明孔茶
確定問題沒有什麼別的要求??比如說111可以是二進位制也可以是八進位制和十六進位制。。。
13樓:匿名使用者
有一個轉換函式很好用:
char *itoa(int value, char *string, int radix);
int value 被轉換的整數,char *string 轉換後儲存的字元陣列,int radix 轉換進位制數,如2,8,10,16 進位制等
標頭檔案: itoa操作使用
但注意:這個不是c++標準庫函式,只能在visual c++系列編譯器環境下使用
想在gcc上做的話,可以設定輸出格式,也可以自己編函式進行轉換……
14樓:匿名使用者
有輸出格式設定的,
#include
#include
int main()
C編寫程式,將使用者輸入的十進位制整數轉換成任意進位制的
1 首先,定義四個整型變數,儲存十進位制整數 二進位制整數等計算值。2 給變數i和二進位制數賦初值,值為0。3 接著,輸入一個十進位制整數。4 用while語句判斷,條件為十進位制數是否為零。5 當十進位制數不為零時,對十進位制數用2求餘,儲存在變數d中。6 十進位制數除以2,使數值縮小為原來的二分...
用C語言編寫程式 將十進位制的數轉化成二進位制的數,並且要用到呼叫函式
float zhuanhuan float num zhengshu for int i 0 i 10 i 要10位小數return zhengshu 請查一相怎麼轉換成float 型別 include void change int x change x 1 printf d x 1 int ma...
編寫C程式,要求使用者輸入十進位制正整數,然後分別轉換成為二進位制數,八進位制數和十六進位制數輸出
int num 10 數字10轉換如下string result1 convert.tostring num,2 二進位制結果為 1010 string result2 convert.tostring num,8 八進位制結果為 12 string result3 convert.tostring...