已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
高精度 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:array1.maxlen of integer s1 is the lowest position slen is the highest position end;var x:array1.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.si); 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); xj.len:=length(st); for i:=1 to xj.len do change string to HP xj.si:=ord(stxj.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.si,a.si+b.si); if c.si=10 then begin dec(c.si,10); inc(c.si+1); add 1 to a higher position end; end; if c.slen+10 then inc(len); c.len:=len; end; procedure main; begin Plus(x1,x2,y); end; procedure out; begin assign(output,fn_out); rewrite(output); PrintHP(y); writeln; close(output); end; begin init; main; out; end.*高精度 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:array1.maxlen of integer s1 is the lowest position slen is the highest position end;var x:array1.2 of hp; y:hp; x:input ; y:output positive:boolean; procedure PrintHP(const p:hp); var i:integer; begin for i:=p.len downto 1 do write(p.si); 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); xj.len:=length(st); for i:=1 to xj.len do change string to HP xj.si:=ord(stxj.len+1-i)-ord(0); end; close(input); end; procedure Subtract(a,b:hp;var c:hp); c:=a-b, suppose 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 subtract from low to high begin inc(c.si,a.si-b.si); if c.si1) and (c.slen=0) do dec(len); c.len:=len; end; function Compare(const a,b:hp):integer; 1 if ab 0 if a=b -1 if ab.len then len:=a.len get the bigger length of a,b else len:=b.len; while(len0) and (a.slen=b.slen) do dec(len); find a position which have a different digit if len=0 then compare:=0 no difference else compare:=a.slen-b.slen; end; procedure main; beginif Compare(x1,x2)1) and (c.slen=0) do dec(len); c.len:=len; end; procedure main; begin Multiply(x,z,y); end; procedure out; begin assign(output,fn_out); rewrite(output); PrintHP(y); writeln; close(output); end; begin init; main; out; end.高精度 4 : 乘法 2 : 高精度数 x 高精度数program HighPrecision4_Multiply2;const fn_inp=hp4.inp; fn_out=hp4.out; maxlen=100; max length of the number type hp=record len:integer; length of the number s:array1.maxlen of integer s1 is the lowest position slen is the highest position end;var x:array1.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.si); 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); xj.len:=length(st); for i:=1 to xj.len do change string to HP xj.si:=ord(stxj.len+1-i)-ord(0); end; close(input); end; procedure Multiply(a,b:hp;var c:hp); c:=a+b var i,j,len:integer; begin fillchar(c,sizeof(c),0); for i:=1 to a.len do for j:=1 to b.len do begin inc(c.si+j-1,a.si*b.sj); inc(c.si+j,c.si+j-1 div 10); c.si+j-1:=c.si+j-1 mod 10; end; len:=a.len+b.len+1; the product of a number with i digits and a number with j digits can only have at most i+j+1 digits while(len1)and(c.slen=0) do dec(len); c.len:=len; end; procedure main; begin Multiply(x1,x2,y); end; procedure out; begin assign(output,fn_out); rewrite(output); PrintHP(y); writeln; close(output); end; begin init; main; out; end.*高精度 5 : 除法 1 : 高精度数 / 单精度数 program HighPrecision3_Multiply1;const fn_inp=hp5.inp; fn_out=hp5.out; maxlen=100; max length of the number type hp=record len:integer; length of the number s:array1.maxlen of integer s1 is the lowest position slen is the highest position end;var x,y:hp; z,w:integer; procedure PrintHP(const p:hp); var i:integer; begin for i:=p.len downto 1 do write(p.si); end; procedure init; var st:string; i:integer; begin assign(input,fn_inp); reset(input); readln(st); x.len:=length(st); for i:=1 to x.len do change string to HP x.si:=ord(stx.len+1-i)-ord(0); readln(z); close(input); end; procedure Divide(a:hp;b:integer;var c:hp;var d:integer); c:=a div b ; d:=a mod b var i,len:integer; begin fillchar(c,sizeof(c),0); len:=a.len; d:=0; for i:=len downto 1 do from high to low begin d:=d*10+a.si; c.si:=d div b; d:=d mod b; end; while(len1) and (c.slen=0) do dec(len); c.len:=len; end; procedure main; begin Divide(x,z,y,w); end; procedure out; begin assign(output,fn_out); rewrite(output); PrintHP(y); writeln; writeln(w); close(output); end; begin init; main; out; end.高精度 6 : 除法 2 : 高精度数 / 高精度数program HighPrecision4_Multiply2;const fn_inp=hp6.inp; fn_out=hp6.out; maxlen=100; max length of the number type hp=record len:integer; length of the number s:array1.maxlen of integer s1 is the lowest position slen is the highest position end;var x:array1.2 of hp; y,w:hp; x:input ; y:output procedure PrintHP(const p:hp); var i:integer; begin for i:=p.len downto 1 do write(p.si); 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); xj.len:=length(st); for i:=1 to xj.len do change string to HP xj.si:=ord(stxj.len+1-i)-ord(0); end; close(input); end; procedure Subtract(a,b:hp;var c:hp); c:=a-b, suppose 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 subtract from low to high begin inc(c.si,a.si-b.si); if c.si1) and (c.slen=0) do dec(len); c.len:=len; end; function Compare(const a,b:hp):integer; 1 if ab 0 if a=b -1 if ab.len then len:=a.len get the bigger length of a,b else len:=b.len; while(len0) and (a.slen=b.slen) do dec(len); find a position which have a different digit if len=0 then compare:=0 no difference else compare:=a.slen-b.slen; end; procedure Multiply10(var a:hp); a:=a*10 var i:Integer; begin for i:=a.len downto 1 do
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 贵港中环生物科技扩建项目环境影响报告表
- 八年级下册《北冥有鱼》过关训练-2024年中考语文课内文言文要点梳理与练习解析版
- 年产40万套新能源汽车电池盒组件项目可行性研究报告模板-申批备案
- 中级微观期末试题及答案
- 2025年高州初一政治试卷及答案
- 2025年大学植物地衣试题及答案
- 资产交接应急预案(3篇)
- 2025年上海舞蹈留学真题及答案
- 2025年星球地理七上题库及答案
- 基于区块链的跨境支付-第2篇-洞察与解读
- 认知域作战基础知识课件
- 大学生职业规划大赛《智能焊接技术专业》生涯发展展示
- 养老社区课件
- 学校流感宣传教学课件
- 车辆管理档案及相关表格
- 矿区钻探安全管理制度
- 德云社空降人员管理制度
- 2022浙DT9 民用建筑常用水泵和风机控制电路图
- 2024年江苏公务员考试申论试题(B卷)
- 工艺报警分级管理制度
- 2025+CSCO结直肠癌诊疗指南解读
评论
0/150
提交评论