High-precision multiplier (PASCAL) algorithm

xiaoxiao2021-03-06  57

I. High-precision multiplication basic ideas and addition. The basic process is as follows:

1 Read the multiplier S1, multiplier S2

2 divide S1, S2 into 4 digits, and there is a number of groups A, B; note the lengths K1, K2 of A, B;

3i is the lowest position in B;

4 Take the i-th bits from B and the multiplication of A, accumulate to another array C;

? )

5i: = i-1; detect I value: less than K2 turn 6, otherwise turn 4

6 print results

Example: Program Download

Program chengfa;

Const n = 100;

TYPE AR = array [1..n] of integer;

VAR A, B: AR; K1, K2, K: Inteder

C: array [1..200] of integer;

S1, S2: STRING;

Procedure fenge (s: string; var; var kk: integer);

VAR SS: STRING;

I, Code: Integer;

Begin

I: = Length (s);

KK: = N;

Repeat

SS: = COPY (S, I-3, 4);

VAL (SS, D [KK], CODE);

KK: = KK-1;

S: = COPY (S, 1, I-4);

I: = I-4;

Until i <0;

KK: = KK 1;

END;

Procedure daying;

VAR i: integer;

Begin

Write (C [k]);

For i: = k 1 to 2 * n do begin

IF C [I] <1000 Then Write ('0');

IF C [I] <100 Then Write ('0');

IF C [i] <10 Then Write ('0');

Write (C [i]);

END;

Writeln;

END;

Begin

Init;

Jisuan;

DAYING;

End.

转载请注明原文地址:https://www.9cbs.com/read-113788.html

New Post(0)