作业帮 > 综合 > 作业

将一个M进制数转换为N进制数 PASCAL

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/14 03:58:57
将一个M进制数转换为N进制数 PASCAL
输入仅一行,分别是M、待转换的M进制数和N,两两之间用一个空格相隔
输入:8 154 16
则输出:6C
用字符串做.
将一个M进制数转换为N进制数 PASCAL
绝对没问题!
program change;
var i,m,n,v,t:longint;
ch:char;
num:string;
begin
assign(input,'change.in');
reset(input);
assign(output,'change.out');
rewrite(output);
readln(n);
readln(num);
readln(m);
v:=0;
for i:=1 to length(num) do
begin
case num[i] of
'0':t:=0;
'1':t:=1;
'2':t:=2;
'3':t:=3;
'4':t:=4;
'5':t:=5;
'6':t:=6;
'7':t:=7;
'8':t:=8;
'9':t:=9;
'A':t:=10;
'B':t:=11;
'C':t:=12;
'D':t:=13;
'E':t:=14;
'F':t:=15
end;
v:=v*n+t
end;
num:='';
while v0 do
begin
case v mod m of
0:ch:='0';
1:ch:='1';
2:ch:='2';
3:ch:='3';
4:ch:='4';
5:ch:='5';
6:ch:='6';
7:ch:='7';
8:ch:='8';
9:ch:='9';
10:ch:='A';
11:ch:='B';
12:ch:='C';
13:ch:='D';
14:ch:='E';
15:ch:='F'
end;
num:=ch+num;
v:=v div m
end;
writeln(num);
close(input);
close(output);
end.