Pascal. Символы и строки. Задача 11

Составьте программу, которая преобразует, введенное пользователем число двоичной системы в равное ему десятичное.

Решение:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
program characters_and_strings_11;
uses crt;
var
bin_str: string;
i, x, n, _int: integer;
dec: real;
begin
clrscr; randomize;
write(‘Введите число в ДС > ‘); read(bin_str);
dec:=0; x:=0; n:=length(bin_str);
for i:=n downto 1 do
begin
_int:=ord(bin_str[i]);
if (_int=48) then dec:=dec+0
else if (_int=49) then dec:=dec+(1*(exp(ln(2)*x)))
else begin write(»); exit end;
x:=x+1;
end;
write(bin_str,‘ в десятичной СС = ‘, dec);
readkey;
end.
Рейтинг
( Пока оценок нет )
Загрузка ...