#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <strings.h>
#include <assert.h>
#include <ctype.h>
#include <wchar.h>
char *bintodec(char* , char* );
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char *bin, *dec;
bin=(char*)malloc(100*sizeof(char));///выделяем память в куче
dec=(char*)malloc(100*sizeof(char));
printf("Введите двоичную запись числа: ");
gets(bin);
printf("Результат: ");
puts(bintodec(bin, dec));
system("pause");
return 0;
}
char *bintodec(char* bin, char* dec){
int b=0, c=1, i, length=strlen(bin); ///длина строки
for(i=length-1; i>=0; i--)
{
b+=c*(bin[i]-'0'); ///символ в число
c*=2;
}
sprintf (dec, "%d", b);
return dec;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.