程序可运行但提示有错,请高手帮看看
将十六进制转换为十进制数 可以运行得出结果,但提示有错,帮看看 ,谢谢#include "stdio.h"
#include "string.h"
#define N 16
main()
{int jiance(char,int);
void zhuanhuan(char,int);
long qiucifang(int);
char a[1000];
int b,c;
printf("请输入一个十六进制数:");
gets(a);
b=strlen(a);
c=jiance(a,b);
if(c==1)
zhuanhuan(a,b);
}
int jiance(char A[],int B) //检测是否输入错误
{int i,,j;
for(i=0;i<B;i++)
if(!(A[i]>='0'&&A[i]<='9'||A[i]>='A'&&A[i]<='F'))
{printf("输入错误!");
j=0;break;}
else
j=1;
return(j);
}
void zhuanhuan(char A[],int B) //转换为十进制
{long Total=0;
int i,zhishu;
for(i=0,zhishu=(B-1);i<B;i++,zhishu--)
switch(A[i])
{case 'A':Total=Total+10*qiucifang(zhishu);break;
case 'B':Total=Total+11*qiucifang(zhishu);break;
case 'C':Total=Total+12*qiucifang(zhishu);break;
case 'D':Total=Total+13*qiucifang(zhishu);break;
case 'E':Total=Total+14*qiucifang(zhishu);break;
case 'F':Total=Total+15*qiucifang(zhishu);break;
default: Total=Total+(A[i]-'0')*qiucifang(zhishu);break}
printf("该数转换为十进制数为%ld.",Total);
}
long qiucifang(int Zhishu) //求16次方
{long total;
if(Zhishu==0)
total=1;
else
if(Zhishu==1)
total=N;
else
total=N*qiucifang(Zhishu-1);
return(total);
}
[[italic] 本帖最后由 llp108 于 2007-12-8 23:54 编辑 [/italic]]