)定義一個將十進制數(shù)轉(zhuǎn)換成十六進制數(shù)的函數(shù)void dec_to_hex(int n),該函數(shù)的功能是將參數(shù)中的十進制數(shù)以十六進制方式輸出。在主函數(shù)輸入一個十進制整數(shù),然后調(diào)用dec2hex()輸出對應(yīng)的十六進制數(shù)。
#include <stdio.h>
_________⑴__________; //?dec_to_hex函數(shù)的聲明
int main()
{
int n,rem;
printf("Enter n: ");
scanf("%d",&n);
printf("\n十進制數(shù):%d 轉(zhuǎn)換為十六進制數(shù)是:",n);
______⑵_______;?// dec_to_hex函數(shù)的調(diào)用
printf("\n");
return 0;
}
void dec_to_hex?(int n)
{
char num[20];
int rem,i=0;
do
{
rem=n%16; ??//存放余數(shù)
n=n/16;
if (rem<10)
_____⑶_____?//10以內(nèi)的數(shù)字轉(zhuǎn)換成對應(yīng)的字符存放在字符數(shù)組num[]中
else
____⑷_____?//10以上的數(shù)字轉(zhuǎn)換成對應(yīng)的字符存放在字符數(shù)組num[]中
}while(n>0);
for(i=i-1;i>=0;i--)
printf("%c",num[i]);
printf("\n");
}
1 回答

SUNMOON1
TA貢獻1條經(jīng)驗 獲得超0個贊
#include <stdio.h>; void dec-to-hex(int n)
// dec_to_hex函數(shù)的聲明 int main() { int n,rem; printf("Enter n: "); scanf("%d",&n); printf("\n十進制數(shù):%d 轉(zhuǎn)換為十六進制數(shù)是:",n); dec-to-hex(n) ;// dec_to_hex函數(shù)的調(diào)用 printf("\n"); return 0; } void dec_to_hex (int n) { char num[20]; int rem,i=0; do { rem=n%16; //存放余數(shù) n=n/16; if (rem<10) num[i++]=‘0’+rem;//10以內(nèi)的數(shù)字轉(zhuǎn)換成對應(yīng)的字符存放在字符數(shù)組num[]中 else num[i++]=‘A’+(rem-10);//10以上的數(shù)字轉(zhuǎn)換成對應(yīng)的字符存放在字符數(shù)組num[]中 }while(n>0); for(i=i-1;i>=0;i--) printf("%c",num[i]); printf("\n"); }
- 1 回答
- 0 關(guān)注
- 2155 瀏覽
添加回答
舉報
0/150
提交
取消