c语言编程 将输入的2进制字符串转换为10进制数输出
c语言编程 将输入的2进制字符串转换为10进制数输出
日期:2017-10-09 08:25:15 人气:1
设置一个循环遍历字符串,设置一个初值为0的变量sum记录十进制数,从下标为0开始,作sum*2+该元素-'0'操作,遍历完成后sum即为所求之结果。代码如下:
//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int main(void){ char a[]="1101001011010111000101&qu