[求助]如何将十六进制转为十进制
这样可否???
#include "stdio.h"
main()
{float a=0,b;char h;
h=getchar();
while(h!='\n')
{switch(h)
{case'0':b=0;break;
case'1':b=1;break;
case'2':b=2;break;
case'3':b=3;break;
case'4':b=4;break;
case'5':b=5;break;
case'6':b=6;break;
case'7':b=7;break;
case'8':b=8;break;
case'9':b=9;break;
case'a':b=10;break;
case'b':b=11;break;
case'c':b=12;break;
case'd':b=13;break;
case'e':b=14;break;
case'f':b=15;break;
default:printf("erreor");break;}
a=(a+b)*16;
h=getchar();
}
printf("%f\n",a/16);
}