Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- con: string[16] = '0123456789ABCDEF';
- var
- w,s:char;
- a, X_cel: string; //check-строка с целой/дробной частью
- i, res_cel,pos_toch, res: integer;
- res_drb:real; //почему не интегер? //CH-число из строки
- osn, D_cel, f: integer; //основание,целая цасть
- D_drb: real; //дробная часть
- X_drb: string; //результаты целой и дробной
- CEL_CHA: integer; //целое число в вычислении дробной части
- con1: integer;
- procedure q;
- var
- i:byte;
- begin
- res:=0;
- for i:=1 to 16 do
- if w = con[i] then
- begin
- res:=i-1;
- break;
- end;
- end;
- procedure X_D_cel;
- var
- i, E:integer;
- begin
- E:=1;
- for i:= length(X_cel) downto 1 do
- begin
- w:=X_cel[i];
- q;
- res_cel:=res_cel+res*E;
- E:=E*osn;
- end;
- end;
- procedure X_D_drb;
- var
- i:integer;
- E:real;
- begin
- E:=1/osn;
- for i := 1 to length(X_drb) do
- begin
- w:=X_drb[i];
- q;
- res_drb:=res_drb +res*E;
- E := E / osn;
- end;
- end;
- begin
- writeln('Введите основание');
- readln(osn);
- writeln('Ведите число в ',osn,'-чной форме');
- readln(a);
- if a[1]='-' then
- begin
- s:=a[1];
- a:=copy(a,2,length(a)-1);
- end;
- for i:=1 to length(a)do
- if a[i]>con[osn] then
- begin
- writeln ('число не принадлежит системе');
- exit
- end;
- pos_toch:=pos('.',a);
- if pos_toch<>0 then
- begin
- X_cel:=copy(a,1,pos_toch-1);
- X_drb:=copy(a,pos_toch+1,length(a)-pos_toch);
- end
- else X_cel:=a;
- pos_toch:=pos('.',X_drb);
- if pos_toch<>0 then
- begin
- writeln('обнаружена лишняя точка');
- exit;
- end;
- X_D_cel;
- X_D_drb;
- writeln('Ответ:');
- write(s); write(res_cel+res_drb);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement