㈠ 高精度乘法。输入两个正整数,求它们的积。 中间标注的地方,想了好长时间还很模糊,有没有简单的理解。
(1)为什么要减48?
因为输入的a1,b1是字符串,字符串中的0-9是ascii编码,其中0的ascii编码是48,1是49,以此类推,因此需要减48变成真正的十进制数。
(2)计算过程
程序中模拟的是小学生列竖式计算多位数乘法的过程,即乘数由低位到高位和被乘数每一位相乘,进位累加到高一位(x存储井位数)。
但是程序把最后的累加过程一步完成了,直接保存在c数组中。
㈡ 3.两个数相乘,小数点后位数没有限制,请写一个高精度算法 与大数相乘原理一样,只是调整小数点位
小数是我国最早提出和使用的。早在3世纪,我国古代数学家刘徽在解决一个数学问题时就提出把整数个位以下无法标出名称的部分称为徽数。
小数的名称是13世纪我国元代数学家朱世杰提出的。在13世纪中叶我国出现了低一格表示小数的记法.
在西方,小数出现很晚,直到16世纪,法国数学家克拉维斯首先使用了小数作为整数部分与小数部分分界的记号。
虽然我国对小数的认识远远早于欧洲,但现代数学中所使用的小数的表示法却是从欧洲传入我国的。欧洲关于十进小数的最大贡献者是荷兰工程师斯蒂文(Simon Stevin,1548?1620)。他从制造利息表中体会到十进小数的优越性,因此他竭力主张把十进小数引进到整个算术运算中去,使十进小数有效地参与记数。不过,斯蒂文的小数记法并不高明,如139.654,他写作135⊙6①5②4③,每个数后面圈中的数是用来指明它前面数字位置的,这种表示方法,使小数的形式复杂化,并且给小数的运算带来很大的麻烦。1592年,瑞士数学家布尔基(Jobst Burgi)对此作出较大的改进。他用一空心小圆圈把整数部分和小数部分隔开,比如把36.548表示为36。548,这与现代的表示法已极为接近。大约过了一年,德国的克拉维斯,首先用黑点代替了小圆圈。他在1608年发表的《代数学》中,将他的这一做法公之于世,至此,小数的现代记法才被确立下来。追问我要被老师骂了、做得太简单了、而且文字太少........... 回答再帮你添加一点内容吧,这两个素材你可以适当的做一些整理。
小数点,数学符号,用于在十进制中隔开整数部分和小数部分。
小数点的由来
中国自古以来就使用十进位制计数法,一些实用的计量单位也采用十进制,所以很容易产生十进分数,即小数的概念。第一个将这一概念用文字表达出来的是魏晋时代的刘徽。他在计算圆周率的过程中,用到尺、寸、分、厘、毫、秒 、忽等7个单位;对于忽以下的更小单位则不再命名,而统称为“微数”。
到了宋、元时代,小数概念得到了进一步的普及和更明确的表示。杨辉《日用算法》(1262年)载有两斤换算 的口诀:“一求,隔位六二五;二求,退位一二五”,即1/16=0�0625;2/16=0�125。 这里的“隔位”、“退位”已含有指示小数点位置的意义。秦九韶则将单位注在表示整数部分个位的筹码之下,例如: —Ⅲ—Ⅱ表示13.12寸 寸是世界上最早的小数表示法。
在欧洲和伊斯兰国家,古巴比伦的六十进制长期以来居于统治地位,一些经典科学着作都是采用六十进制,因此十进制小数的概念迟迟没有发展起来。15世纪中亚地区的阿尔卡西(?~1429)是中国以外第一个应用小数的人。欧洲数学家直到16世纪才开始考虑小数,其中较突出的是荷兰人斯蒂文(1548~1620),他在《论十进制》(1583年)一书中明确表示法。例如把5.714记为:5◎7①1②4③或5,7'1''4'''。而第一个把小数表示成今日世界通用的形式的人是德国数学家克拉维斯(1537~1612),他在《星盘》(1593年)一书中开始使用小数点作为整数部分与小数部分之间的分界符。
而中国比欧洲早采用了三百多年。
小数点尽管小,但是作用极大。我们时刻都不可忽略这个小小的符号。因为这个不起眼的差错,人类酿过一个又一个悲剧。正可谓“差之毫厘,谬以千里”。1967年,前苏联“联盟一号”坠毁事件,造成了不可挽回的损失。直接原因是在地面检查时,忽略了一个小数点……导致了数亿元财富的损失,人类还失去了一位太空英雄----科马洛夫的生命! 追问虽然你的内容不错,我也看得懂,可是只能当天做啊......我都交了...算了吧
㈢ 高精度计算的单精度乘法
单精度乘法是计算范围次于高精度乘法的一种运算,只是运算效率略比高精度计算低。
单精度乘法过程样例:
const
maxcount=进制位
maxlen=记录高精度数组大小
procere mulnum(a:bignum;x:longint;,var c:bignum);
var
i:longint;
begin
fillchar(c,sizeof(c),0);c[0]:=a[0];
for i:=1 to c[0] do c[i]:=a[i]*x;
for i:=1 to c[0] do {进位}
begin
inc(c[i+1],c[i] div maxcount);
c[i]:=c[i] mod 10;
end;
while c[c[0]+1]>0 do
begin
inc(c[0]);
inc(c[c[0]+1],c[c[0]] div maxcount);
c[c[0]]:=c[c[0]] mod maxcount;
end;
end;
㈣ 高精度乘法,高精度是什么意思,据说可以一位存好几位
到目前为止,我们这个星球上的任何数字电路中,任何1位的寄存器电路只能存1位数,就是0 或 1,绝对不可能存好几位的啦,高精度是指可以表示的小数点后面的位数比较多,高精度乘法一般是指 浮点乘法,在实际运用中,小数表达一般用的比较少的.只有在交流电机或变频电源里用的比较多.
㈤ Pascal高精度计算,加减乘除
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 }
procere PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procere 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;
procere Plus(a,b:hp;var c:hp); { c:=a+b }
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
if a.len>b.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;
procere main;
begin
Plus(x[1],x[2],y);
end;
procere 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:output }
positive:boolean;
procere PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procere 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;
procere 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.len>b.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.s[i],a.s[i]-b.s[i]);
if c.s[i]<0 then
begin
inc(c.s[i],10);
dec(c.s[i+1]); { add 1 to a higher position }
end;
end;
while(len>1) and (c.s[len]=0) do dec(len);
c.len:=len;
end;
function Compare(const a,b:hp):integer;
{
1 if a>b
0 if a=b
-1 if a<b
}
var len:integer;
begin
if a.len>b.len then len:=a.len { get the bigger length of a,b }
else len:=b.len;
while(len>0) and (a.s[len]=b.s[len]) do dec(len);
{ find a position which have a different digit }
if len=0 then compare:=0 { no difference }
else compare:=a.s[len]-b.s[len];
end;
procere main;
begin
if Compare(x[1],x[2])<0 then positive:=false
else positive:=true;
if positive then Subtract(x[1],x[2],y)
else Subtract(x[2],x[1],y);
end;
procere out;
begin
assign(output,fn_out);
rewrite(output);
if not positive then write('-');
PrintHP(y);
writeln;
close(output);
end;
begin
init;
main;
out;
end.
2.3高精度乘高精度
程序如下:
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: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 }
procere PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procere 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;
procere 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.s[i+j-1],a.s[i]*b.s[j]);
inc(c.s[i+j],c.s[i+j-1] div 10);
c.s[i+j-1]:=c.s[i+j-1] mod 10;
end;
len:=a.len+b.len+1;
{
the proct of a number with i digits and a number with j digits
can only have at most i+j+1 digits
}
while(len>1)and(c.s[len]=0) do dec(len);
c.len:=len;
end;
procere main;
begin
Multiply(x[1],x[2],y);
end;
procere out;
begin
assign(output,fn_out);
rewrite(output);
PrintHP(y);
writeln;
close(output);
end;
begin
init;
main;
out;
end.
2.4 高精度除以高精度
程序如下:
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: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,w:hp; { x:input ; y:output }
procere PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procere 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;
procere 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.len>b.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.s[i],a.s[i]-b.s[i]);
if c.s[i]<0 then
begin
inc(c.s[i],10);
dec(c.s[i+1]); { add 1 to a higher position }
end;
end;
while(len>1) and (c.s[len]=0) do dec(len);
c.len:=len;
end;
function Compare(const a,b:hp):integer;
{
1 if a>b
0 if a=b
-1 if a<b
}
var len:integer;
begin
if a.len>b.len then len:=a.len { get the bigger length of a,b }
else len:=b.len;
while(len>0) and (a.s[len]=b.s[len]) do dec(len);
{ find a position which have a different digit }
if len=0 then compare:=0 { no difference }
else compare:=a.s[len]-b.s[len];
end;
procere Multiply10(var a:hp); { a:=a*10 }
var i:Integer;
begin
for i:=a.len downto 1 do
a.s[i+1]:=a.s[i];
a.s[1]:=0;
inc(a.len);
while(a.len>1) and (a.s[a.len]=0) do dec(a.len);
end;
procere Divide(a,b:hp;var c,d:hp); { c:=a div b ; d:=a mod b }
var i,j,len:integer;
begin
fillchar(c,sizeof(c),0);
len:=a.len;
fillchar(d,sizeof(d),0);
d.len:=1;
for i:=len downto 1 do
begin
Multiply10(d);
d.s[1]:=a.s[i]; { d:=d*10+a.s[i] }
{ c.s[i]:=d div b ; d:=d mod b; }
{ while(d>=b) do begin d:=d-b;inc(c.s[i]) end }
while(compare(d,b)>=0) do
begin
Subtract(d,b,d);
inc(c.s[i]);
end;
end;
while(len>1)and(c.s[len]=0) do dec(len);
c.len:=len;
end;
procere main;
begin
Divide(x[1],x[2],y,w);
end;
procere out;
begin
assign(output,fn_out);
rewrite(output);
PrintHP(y);
writeln;
PrintHP(w);
writeln;
close(output);
end;
begin
init;
main;
out;
end.
㈥ 高精度乘法 pascal
var s:array[1..100] of integer;
k,i,j,n,l:integer;
o:boolean;
begin
readln(n); s[100]:=1;
for i:=1 to n-1 do begin
for j:=100 downto 1 do begin
s[j]:=s[j]*2+k;
if s[j]>9 then begin k:=s[j] div 10; s[j]:=s[j] mod 10; end else k:=0;
end;
end;
for i:=100 downto 1 do
if s[i]>9 then
begin
s[i-1]:=s[i-1]+s[i] div 10;
end;
o:=false;
for l:=1 to 100 do
if (s[l]<>0)or o then begin write(s[l] mod 10); o:=true; end;
writeln; readln;
end.
输入输出样例:
输入:3 {2的2次方}
输出:4 {2的2次方的结果}
输入:100 {2的99次方}
输出: {2的99次方的结果}
㈦ 请帮我解析一下pascal高精度计算的乘法运算。谢谢
读入被乘数s1,乘数s2
把s1、s2分成4位一段,转成数值存在数组a,b中;记下a,b的长度k1,k2;
i赋为b中的最低位;
从b中取出第i位与a相乘,累加到另一数组c中;
i:=i-1;检测i值:小于k2则转⑥,否则转④
㈧ 高精度乘法原理与算法是什么
模拟竖式乘法,逐位相乘,用字符形式储存数字进行计算,结果仍为字符。算法网上都有的。