网站大量收购独家精品文档,联系QQ:2885784924

Pascal语言 高精度计算资料.doc

  1. 1、本文档共13页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Pascal语言 高精度计算资料

高精度计算 2.1 高精度加法 2.2 高精度减法 2.3 高精度乘法 2.4 高精度除法 2.1高精度加法 高精度加法程序如下: program HighPrecision1_Plus; const fn_inp=hp1.inp; fn_out=hp1.out; maxlen=100; { max length of the number } type hp=record len:integer; { length of the number } s:array[1..maxlen] of integer { s[1] is the lowest position s[len] is the highest position } end; var x:array[1..2] of hp; y:hp; { x:input ; y:output } procedure PrintHP(const p:hp); var i:integer; begin for i:=p.len downto 1 do write(p.s[i]); end; procedure init; var st:string; j,i:integer; begin assign(input,fn_inp); reset(input); for j:=1 to 2 do begin readln(st); x[j].len:=length(st); for i:=1 to x[j].len do { change string to HP } x[j].s[i]:=ord(st[x[j].len+1-i])-ord(0); end; close(input); end; procedure Plus(a,b:hp;var c:hp); { c:=a+b } var i,len:integer; begin fillchar(c,sizeof(c),0); if a.lenb.len then len:=a.len { get the bigger length of a,b } else len:=b.len; for i:=1 to len do { plus from low to high } begin inc(c.s[i],a.s[i]+b.s[i]); if c.s[i]=10 then begin dec(c.s[i],10); inc(c.s[i+1]); { add 1 to a higher position } end; end; if c.s[len+1]0 then inc(len); c.len:=len; end; procedure main; begin Plus(x[1],x[2],y); end; procedure out; begin assign(output,fn_out); rewrite(output); PrintHP(y); writeln; close(output); end; begin init; main; out; end. 2. 2 高精度减法 高精度减法程序如下: program HighPrecision2_Subtract; const fn_inp=hp2.inp; fn_out=hp2.out; maxlen=100; { max length of the number } type hp=record len:integer; { length of the number } s:array[1..maxlen] of integer { s[1] is the lowest position s[len] is the highest position } end; var x:array[1..2] of hp; y:hp; { x:input ; y:

文档评论(0)

cj80011 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档