代码如下:
/*
*
*Declaration:The author of <<Accelerated C++>> has wrote in the end of that book: As you look for reading materimal, keep in mind that books on the shelf do not make you a better programmer. Ultimately, the only way to improve your programming is to write programs. >这些程序来自一些ACM书籍,作者只为提高编程能力,实现书中例题或练习。如有侵权,请联系作者,作者将立即删除。
*
*联系邮箱:mingxinglai#gmail.com
*
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char* argv[])
{
int i, k, base[31], sum;
char skew[32];
base[0] = 1;
for( i = 1; i < 31; i++)
base[i] =(int)(pow(2,i+1) - 1);
while(1)
{
scanf("%s",skew);
if( strcmp(skew,"0") == 0) break;
sum = 0;
k = strlen( skew );
for( i = 0; i < strlen( skew ); i++)
{
k--;
sum += (skew[i] - '0') * base[k];
}
printf("%d\n",sum);
}
return 0;
}
本文介绍了一个位偏斜数转换程序的实现方法。通过使用C语言,该程序能够读取用户输入的位偏斜数,并将其转换为对应的十进制数值。程序首先初始化一个基数数组,用于存储位偏斜数的基数,然后读取用户输入的位偏斜数字符串,通过遍历字符串并利用基数进行计算得到最终的十进制数值。
419

被折叠的 条评论
为什么被折叠?



