Программа преобразует, введенное пользователем двоичное «целое» число в десятичное.
Решение:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <math.h>
#include «stdafx.h» #include <iostream> using namespace std; int main() {setlocale(LC_ALL,«Rus»); char bin_str[255]; int dec=0, i, n, _int; float x=0; cout<<» Введите строку >>\n«; cin.getline(bin_str, 255); n=strlen(bin_str); for (i=n—1; i>=0; i—) {_int=bin_str[i]; if (_int==48) dec+=0; else if (_int==49) dec+=(1*(pow(2, x))); else goto exit; //досрочное завершение x++; } cout<<endl<<bin_str<<» в десятичной СС = «<<dec<<endl; exit: cout<<» Нажмите любую клавишу для выхода»; system(«pause>>void»); return 0; } |