[讨论]大家看看怎么玩
8进制转换成10进制 编写函数
字符串好,一般不会溢出。 #include <stdio.h> #include <stdlib.h>
double Octal2Decimal(char *); void main() { char number[30]; double mm = 0.0; printf("Please input the Octal number:"); scanf("%s",number); mm = Octal2Decimal(number); printf("(%s)8 = %lf\n", number, mm); } double Octal2Decimal(char *num) { int depart = 0, i = 1; double floatpart = 0; while(*num != '\0' && *num != '.') { depart = (depart<<3) + *num - '0'; num ++; } if(*num != '\0') { num++; while(*num != '\0') { i = i<<3; floatpart += (*num - '0')/(i*1.0); num++; } } return depart + floatpart; }