❶ c語言10進制轉8進制,程序怎麼寫
include <stdio.h> #include <math.h> #include <stdlib.h> long dtoe(int a); void dtoh(int a,char h[]); int main(void) { long a; char h[80]; scanf("%d",&a); dtoh(a,h); printf("HEX:%s\n",h); a=dtoe(a); printf("OCT:%d\n",a); system("pause"); return 0; } long dtoe(int a) // 八進制 { if (a<8) { return a; } else return (dtoe(a/8)*10+a%8); } 好好學習 不怕考試 !
❷ 一個C語言的問題
#include <stdio.h>
void dtoh(char sour[],char resu[]){
int x; sscanf(sour,"%d",&x); sprintf(resu,"%x",x);
}
void htod(char sour[],char resu[]){
int x; sscanf(sour,"%x",&x); sprintf(resu,"%d",x);
}
int main(){
char d1[20]="16189", h1[20];
char d2[20], h2[20]="3F3D";
dtoh(d1,h1); printf("%s - %s\n",d1,h1);
htod(h2,d2); printf("%s - %s\n",h2,d2);
return 0;
}
❸ 請問:C語言 程序填充(指針):ditoh 會寫嗎
#include"stdio.h"
#include"string.h"
chartrans(intx)
{if(x<10)
return'0'+x;
elsereturn'a'+x-10;
}
intDtoH(intn,char*str)
{inti=0;
while(n!=0)
{
str[i]=trans(n%16);
n/=16;
i++;
}
returni-1;}
voidmain()
{inti,k,n;
charstr[30];
scanf("%d",&n);
k=DtoH(n,str);
for(i=0;i<=k;i++)
printf("%c",str[k-i]);}
❹ void dtoh(int)是什麼意思
這個是一個函數,傳入一個int參數,返回一個空類型!通過函數名不能判斷它的具體用處!謝謝,望採納!
❺ c語言中stdio.h是什麼意思
stdio.h是C語言的頭文件。
在C語言或C++中,會把用來#include的文件的擴展名叫 .h,稱其為頭文件。 #include文件的目的就是把多個編譯單元(也就是c或者cpp文件)公用的內容。
單獨放在一個文件里減少整體代碼尺寸;或者提供跨工程公共代碼。在現行的c++版本中,應用這個頭文件應是#include<stdio.h>。所以,源代碼中如用到標准輸入輸出函數時,就要包含這個頭文件。
(5)c語言Dtoh什麼意思擴展閱讀
C語言stdio.h各函數的用法
fopen:FILE *fopen(const char *filename, const char *mode)
使用給定的模式 mode 打開 filename 所指向的文件。
freopen:FILE *freopen(const char *filename, const char *mode, FILE *stream)
把一個新的文件名 filename 與給定的打開的流 stream 關聯,同時關閉流中的舊文件。
fflush:int fflush(FILE *stream)
刷新流 stream 的輸出緩沖區。
fclose:int fclose(FILE *stream)
關閉流 stream。刷新所有的緩沖區。
❻ 我想學習C語言,代碼基本能看懂,但是涉及到各種進制數轉換、「^」、「~」等等這些方面的計算很難理。
代碼能看懂就容易上手了,關於你說的數制轉換多花點功夫就會解決的,因為都有他的方法,多看看,多練習。還有一個重要的問題就是演算法,希望你能好好理解,演算法好了就成功了70%。
❼ c語言10進制轉8進制以及16進制的源程序
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long dtoe(int a);
void dtoh(int a,char h[]);
int main(void)
{ long a;
char h[80];
scanf("%d",&a);
dtoh(a,h);
printf("HEX:%s\n",h);
a=dtoe(a);
printf("OCT:%d\n",a);
system("pause");
return 0;
}
long dtoe(int a) // 八進制
{
if (a<8) {
return a;
}
else
return (dtoe(a/8)*10+a%8);
}
void dtoh(int a,char h[]) //十六進制
{
int i;
i=(int)(log(a)/log(16));
h[i+1]=0;
while (a>15) {
if (a%16<10) h[i--]=48+(a%16);
else h[i--]=55+(a%16);
a/=16;
}
if (a>9) h[i]=55+a%16;
else h[i]=48+a%16;
}
***************************************
有什麼問題?
是否可以一次把問題描述清楚??
已修正,可以在低版本的TC(如TC++3.0)中運行。
***************************************
在低版本的TC(如TC2\3.0)中不要使用中文,以免對程序的兼容性造成不良影響。
請將問題描述清楚一些好嗎??
「還有那個運行到[就出錯了.」 是什麼意思?
你在什麼版本的TC中運行的?
***************************************
你描述的警告我已經去掉了,應該不會出現這些警告了和錯誤了,
我在TC++3.0中測試時沒有出現任何警告和錯誤,懷疑是你的TC的問題,請盡量使用原版,不要再使用這些非官方的漢化版了
以下是原版TC++3.0 的下載地址:
http://www.wangxvdong.cn/files/TC30.rar
❽ c語言將一個無符號數轉換為任意x進制數
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long dtoe(int a);
void dtoh(int a,char h[]);
int main(void)
{ long a;
char h[80];
scanf("%d",&a);
dtoh(a,h);
printf("HEX:%s\n",h);
a=dtoe(a);
printf("OCT:%d\n",a);
system("pause");
return 0;
}
long dtoe(int a) // 八進制
{
if (a<8) {
return a;
}
else
return (dtoe(a/8)*10+a%8);
}
void dtoh(int a,char h[]) //十六進制
{
int i;
i=(int)(log(a)/log(16));
h[i+1]=0;
while (a>15) {
if (a%16<10) h[i--]=48+(a%16);
else h[i--]=55+(a%16);
a/=16;
}
if (a>9) h[i]=55+a%16;
else h[i]=48+a%16;
}
❾ C語言:編程實現將輸入的十進制整數n通過函數DtoH轉換為十六進制數,並將轉換結果以字元形式輸出。
問題不少,首先,10進制不能直接轉化為16進制,應該先轉為2進制然後再轉16進制,其次,char *str 用法錯誤,只分配了一個字元指針,你卻當字元數組使用了,把這兩處改了去。