高
高
精
精
度
度
运
运
算
算
转换数据类型
加法运算
减法运算
乘法运算
除法运算
数据类型的转换
在变量运算对象的数值范围为任何数据类型所
无法容纳的情况下,采用整数数组(每一个元素
对应一位十进制数,由其下标顺序指明位序号
)。
1、采用数串形式输入,并将其转化为整数数组。
2、该数组的运算规则如同算术运算。
3、用一个整数变量记录数据的实际长度(即数组的
元素个数)
加法运算c←a+b(a、b、c为numtype类型)
var
a,b,c:array[1..201] of 0..9;
n:string;
lena,lenb,lenc,i,x:integer;
begin
write('Input augend:'); readln(n);lena:=length(n); for i:=1 to lena do a[lena
-i+1]:=ord(n[i])-ord('0');{加数放入a数组}
write('Input addend:'); readln(n); lenb:=length(n); for i:=1 to lenb do
b[lenb-i+1]:=ord(n[i])-ord('0');{被加数放入b数组}
i:=1;
while (i<=lena) or(i<=lenb) do
begin
x := a[i] + b[i] + x div 10; {两数相加,然后加前次进位}
c[i] := x mod 10; {保存第i位的值}
i := i + 1
end;
if x>=10 {处理最高进位}
then begin lenc:=i; c[i]:=1 end
else lenc:=i-1;
for i:=lenc downto 1 do write(c[i]); writeln {输出结果}
end.