




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、高精度計(jì)算2.1高精度加法2.2高精度減法2.3高精度乘法2.4高精度除法2.1高精度加法高精度加法程序如下:program HighPrecision1_Plus;constfn_inp=hp1.inp;fn_out=hp1.out;maxlen=100; max length of the number typehp=recordlen:integer; length of the number s:array1.maxlen of integer s1 is the lowest position slen is the highest position end;varx:array1.
2、2 of hp;y:hp; x:input ; y:output procedure PrintHP(const p:hp);var i:integer;beginfor i:=p.len downto 1 do write(p.si);end;procedure init;varst:string;j,i:integer;beginassign(input,fn_inp);reset(input);for j:=1 to 2 dobeginreadln(st);xj.len:=length(st);for i:=1 to xj.len do change string to HP xj.si
3、:=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;beginfillchar(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 begininc(c.si,a.si+b.si);if c.si=10 thenbegindec(
4、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;beginPlus(x1,x2,y);end;procedure out;beginassign(output,fn_out);rewrite(output);PrintHP(y);writeln;close(output);end;begininit;main;out;end.2. 2高精度減法高精度減法程序如下: program HighPrecision2_Sub
5、tract;constfn_inp=hp2.inp;fn_out=hp2.out;maxlen=100; max length of the number typehp=recordlen:integer; length of the number s:array1.maxlen of integer s1 is the lowest positionslen is the highest position end;varx:array1.2 of hp;y:hp; x:input ; y:output positive:boolean;procedure PrintHP(const p:hp
6、);var i:integer;beginfor i:=p.len downto 1 do write(p.si);end;procedure init;varst:string;j,i:integer;beginassign(input,fn_inp);reset(input);for j:=1 to 2 dobeginreadln(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 Sub
7、tract(a,b:hp;var c:hp); c:=a-b, suppose a=b var i,len:integer;beginfillchar(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 begininc(c.si,a.si-b.si);if c.si1) and (c.slen=0) do dec(len);c.len:=len;end;function C
8、ompare(const a,b:hp):integer;(1 if ab0 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;
9、beginif Compare(x1,x2)=10) dobegininc(c.slen+1,c.slen div 10);c.slen=c.slen mod 10;inc(len);end;while(len1) and (c.slen=0) do dec(len);c.len:=len;end;procedure main;beginMultiply(x,z,y);end;procedure out;beginassign(output,fn_out);rewrite(output);PrintHP(y);writeln;close(output);end;begininit;main;o
10、ut;end.2.高精度乘一個(gè)整型數(shù)據(jù)(integer)只需要將上述程序的hp類(lèi)型定義如下即可:typehp=recordlen:integer ( length of the number s:array1.maxlen of longint( s1 is the lowest position slen is the highest position end;3.高精度乘高精度程序如下:program HighPrecision4_Multiply2;constfn_inp=hp4.inp;fn_out=hp4.out;maxlen=100; ( max length of the num
11、ber typehp=recordlen:integer; ( length of the number s:array1.maxlen of integer( s1 is the lowest position slen is the highest position end;varx:array1.2 of hp;y:hp; ( x:input ; y:output procedure PrintHP(const p:hp);var i:integer;beginfor i:=p.len downto 1 do write(p.si);end;procedure init;varst:st
12、ring;j,i:integer;beginassign(input,fn_inp);reset(input);for j:=1 to 2 dobeginreadln(st);xj.len:=length(st);for i:=1 to xj.len do ( change string to HP 2.4高精度除法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;beginfillchar(c,sizeof(c
13、),0);for i:=1 to a.len dofor j:=1 to b.len dobegininc(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 digitscan only have at most i+j+1 digitswhile(len1)and(c.slen=0) do dec(len);c.len:=len;end
14、;procedure main;beginMultiply(x1,x2,y);end;procedure out;beginassign(output,fn_out);rewrite(output);PrintHP(y);writeln;close(output);end;begininit;main;out;end.1.高精度除以整型數(shù)據(jù)(integer);程序如下:program HighPrecision3_Multiply1;constfn_inp=hp5.inp;fn_out=hp5.out;maxlen=100; max length of the number typehp=re
15、cordlen:integer; length of the number s:array1.maxlen of integer s1 is the lowest position slen is the highest position end;varx,y:hp;z,w:integer;procedure PrintHP(const p:hp);var i:integer;beginfor i:=p.len downto 1 do write(p.si);end;procedure init;varst:string;i:integer;beginassign(input,fn_inp);
16、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;beginfillchar(c,sizeof(c),0);len:=a.len;d:=0;for i:=len downt
17、o 1 do ( from high to low begind:=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;beginDivide(x,z,y,w);end;procedure out;beginassign(output,fn_out);rewrite(output);PrintHP(y);writeln;writeln(w);close(output);end;begininit;main;out;end.2.高精度
18、除以高精度程序如下:program HighPrecision4_Multiply2;constfn_inp=hp6.inp;fn_out=hp6.out;maxlen=100; ( max length of the number typehp=recordlen:integer; ( length of the number s:array1.maxlen of integer( s1 is the lowest positionslen is the highest position end;varx:array1.2 of hp;y,w:hp; ( x:input ; y:output
19、 procedure PrintHP(const p:hp);var i:integer;beginfor i:=p.len downto 1 do write(p.si);end;procedure init;varst:string;j,i:integer;beginassign(input,fn_inp);reset(input);for j:=1 to 2 dobeginreadln(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
20、;close(input);end;procedure Subtract(a,b:hp;var c:hp); ( c:=a-b, suppose a=b var i,len:integer;beginfillchar(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 begininc(c.si,a.si-b.si);if c.si1) and (c.slen=0) do
21、 dec(len);c.len:=len;end;function Compare(const a,b:hp):integer;(1 if ab0 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:I
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 面對(duì)考試監(jiān)理工程師的策略試題及答案
- 2025-2030壁櫥項(xiàng)目商業(yè)計(jì)劃書(shū)
- 2025-2030塑料土工格柵行業(yè)市場(chǎng)現(xiàn)狀供需分析及重點(diǎn)企業(yè)投資評(píng)估規(guī)劃分析研究報(bào)告
- 2025-2030土木建筑產(chǎn)業(yè)市場(chǎng)發(fā)展分析及前景趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 2025-2030國(guó)內(nèi)高級(jí)建材行業(yè)市場(chǎng)發(fā)展分析及發(fā)展前景與投資機(jī)會(huì)研究報(bào)告
- 2025-2030國(guó)內(nèi)瓷磚行業(yè)市場(chǎng)發(fā)展分析及發(fā)展前景與投資機(jī)會(huì)研究報(bào)告
- 2025-2030國(guó)內(nèi)有機(jī)農(nóng)產(chǎn)品行業(yè)市場(chǎng)發(fā)展分析及競(jìng)爭(zhēng)格局與發(fā)展策略研究報(bào)告
- 2025-2030噴氣燃料行業(yè)市場(chǎng)現(xiàn)狀供需分析及重點(diǎn)企業(yè)投資評(píng)估規(guī)劃分析研究報(bào)告
- 2025-2030商品證券行業(yè)市場(chǎng)深度分析及發(fā)展策略研究報(bào)告
- 預(yù)算員跨界學(xué)習(xí)的探討試題及答案
- 臨邊防護(hù)安全培訓(xùn)課件
- 專(zhuān)題04-完形填空2023年高考英語(yǔ)三模試題分項(xiàng)匯編(新高考八省專(zhuān)用)-(原卷版)
- 詩(shī)詞接龍完整版本
- 上海市2024年中考英語(yǔ)試題及答案
- 房屋市政工程生產(chǎn)安全重大事故隱患判定標(biāo)準(zhǔn)(2024版)宣傳畫(huà)冊(cè)
- 湖北省黃岡八模2025屆高三第一次模擬考試數(shù)學(xué)試卷含解析
- 2024-2030年中國(guó)建筑垃圾處理行業(yè)發(fā)展分析及投資規(guī)劃研究報(bào)告
- DB11∕T 1842-2021 市政基礎(chǔ)設(shè)施工程門(mén)式和橋式起重機(jī)安全應(yīng)用技術(shù)規(guī)程
- 2025年湖北省武漢市高考數(shù)學(xué)模擬試卷附答案解析
- 部編版五年級(jí)語(yǔ)文上冊(cè)快樂(lè)讀書(shū)吧測(cè)試題及答案
- 心肺復(fù)蘇考試題及答案
評(píng)論
0/150
提交評(píng)論