正在加载图片...
include <iostream> using namespace std; double power (double x, int n)i void main(void) in七i int value =0 char ch cout < Enter an 8 bit binary number i f。r(i=7;i>=0; cin >> ch if (ch 11) value + int(power (2, i))i cout << Decimal value is <<value<<endl double power (double x, int n) double val 1.0; 运行结果: Enter an 8 bit binary number while (n--) va1*=x;01101001 return(val) Decimal value is 105#include <iostream> using namespace std; double power (double x, int n); void main(void) { int i; int value = 0; char ch; cout << "Enter an 8 bit binary number "; for (i = 7; i >= 0; i--) { cin >> ch; if (ch == '1') value += int(power(2,i)); } cout <<"Decimal value is "<<value<<endl; } double power (double x, int n) { double val = 1.0; while (n--) val *= x; return(val); } 运行结果: Enter an 8 bit binary number 01101001 Decimal value is 105 9
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有