编程中,怎样把123和456合成一个数字123456。(pascal语言)

2025年03月23日 09:04
有6个网友回答
网友(1):

方法一、(DELPHI下调试通过)

program test; {$apptype console}
uses sysutils;
var x,y,z,i: integer;
begin
x:=123;
y:=456;
val(inttostr(x)+inttostr(y),z,i);
writeln(z);
end.

方法二、(几乎所有PASCAL通用)
program test; {$apptype console}
var x,y,z: integer;
begin
x:=123;
y:=456;
if y>10000 then z:=x*100000+y
else if y>1000 then z:=x*10000+y
else if y>100 then z:=x*1000+y
else if y>10 then z:=x*100+y
else z:=x*10+y;
writeln(z);
end.

网友(2):

把123和456都转化成字符串
再把两个字符串连起来
再把连起来后的字符串转成数值型

网友(3):

very easy
第一种方法:
var c:integer;
begin
c:=123*1000+456;
end;
另一种方法:
var c:string;number,co:integer;
begin
c:='123'+'456';
val(c,number,co);
end.
以上程序中c为结果

网友(4):

太简单的,
begin
writeln('123456');
readln;
end.

网友(5):

var
a,b,c:string;
begin
readln(a);
readln(b);
c:=a+b;
writeln(c);
end.

网友(6):

a:=123;
b:=456;
c:=a*1000+b;
writeln(c);