Not Yet Answered # urgent

radu84 4 ~Paul~ 7 Discussion Starter leaf Discussion Starter leaf Discussion Starter leaf LLC

0

need a help on multiply a hundred digit to a hundred digit

ok, and how someone can help you, if you don't specify the entire problem?

0

I think he wants to have an integer = 0 then add one number at a time until the integer reaches 100? Is that it leaf?

0

a whole code for multiply in pascal. like:

(1245789632541254789658745123654789582346587985213658234589541236985754698521302102104587036524125968)*(1230214578965874520321014785023698524702654852389502135478950231456987525845256325402135698520324569)

a hundred digit by a hundred digit

0

probably:) who knows....we wait until he post again!

(1245789632541254789658745123654789582346587985213658234589541236985754698521302102104587036524125968)*(1230214578965874520321014785023698524702654852389502135478950231456987525845256325402135698520324569)

a hundred digit by a hundred digit

0

(1245789632541254789658745123654789582346587985213658234589541236985754698521302102104587036524125968)*(1230214578965874520321014785023698524702654852389502135478950231456987525845256325402135698520324569)

a hundred digit by a hundred digit

0

Here is the Algorithm. I based on the model of multiplying decimal natural numbers of fixed capacity. And this caused a problem with overflow. So an additional code is needed to control owerflow and save all significant digits in mantissa. The code will work both in Turbo Pascal and Delphi, but in Delphi we can use open arrays and with their help provide the variable length of the type LNumber.

```
const MaxDigits=10;
type LNumber = array[1..MaxDigits] of byte;
var
Form2: TForm2;
A,B,R:LNumber;
procedure Clear(var A:LNumber);
var i:integer;
begin
for i := MaxDigits downto 1 do A[i]:=0;
end;
Procedure ShiftR(var A: LNumber; Shift:Integer);
var i:Integer;
begin
{performing right shift}
for i := MaxDigits downto 1 + Shift do A[i]:=A[i-Shift];
for i := Shift downto 1 do A[i]:=0;{setting remaining left bytes to zero}
end;
Procedure ShiftL(var A: LNumber; Shift: integer; var BytesOver: integer);
{Shift - Number of bytes to shift}
{BytesOver - Number of bytes exceeded the capacity of LNumber}
var i:Integer;BytesFree,n:integer;
begin
i:=1;BytesFree:=0;BytesOver:=0;
{searching for the amount of the leading zeroes}
while A[i] = 0 do begin i:=i+1;inc(BytesFree);end;
if BytesFree>Shift then n:=Shift else n:=BytesFree;
{performing left shift}
for i := 1 to MaxDigits - n do A[i]:=A[i+n];
{Setting the remaining right bytes to zero}
for i := MaxDigits - n + 1 to MaxDigits do A[i]:=0;
if Shift>BytesFree then BytesOver:=Shift-BytesFree;
end;
procedure Add(var A, B, R: LNumber; flag: integer);
var i, C, OverFlag:Integer;
{adds A and B and stores the result in R (R:=A+B)}
{add(A,B,A) is equal to A:=A+B}
{flag = 1 overflow }
begin
OverFlag:=0;
for i := MaxDigits downto 1 do
begin
C:=A[i]+B[i] + OverFlag;
R[i]:=C mod 10;{the right digit of sum}
OverFlag := C div 10;{OverFlag = 1 if C>9}
end;
end;
procedure MulD(var A: LNumber; B: byte;var R: LNumber; var OverFlag: integer);
{Multiplies A by the decimal digit, the product is stored in R}
{OverFlag = 1 overflow}
var i, C:Integer;
begin
OverFlag:=0;
for i := MaxDigits downto 1 do
begin
C := A[i]*B + OverFlag;
R[i] := C mod 10; {the right digit of the product}
OverFlag := C div 10;
end;
if OverFlag > 0 then
begin
ShiftR(R,1); R[1]:=OverFlag;OverFlag:=1;
end;
end;
procedure Mul(var A, B, R: LNumber;var Mult:integer);
{Multiplies A by B}
{Mult shows the amount of the truncated digits}
var j, OverFlag, BytesOver, Multiple1, MultipleR:Integer;
A1, A2:LNumber;
O:integer;
begin
Clear(R);
MultipleR:=0;
for j := MaxDigits downto 1 do
if B[j]<>0 then
begin
MulD(A, B[j], A1, OverFlag);
ShiftL(A1, MaxDigits-j, BytesOver);
Multiple1:=BytesOver+OverFlag;
ShiftR(R,Multiple1-MultipleR);
ADD(A1, R, R, OverFlag);
MultipleR:=Multiple1 + OverFlag;
end;
Mult:=MultipleR;
end;
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I don’t want at this stage work on a big separate project as I've already got plenty ...

I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:

```
try
{
Runtime run = Runtime.getRuntime();
Process pr = ...
```

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`