Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Multiplying two large numbers in Turbo Pascal

jokarcsjokarcs iranMember Posts: 1

Hello friends, I am new in turbo pascal and I want to write a code that multiplies two large numbers each has 20 digits. I think I should use arrays, right?!
Thanks for you help.

Answers

  • StupidKidStupidKid VietnamMember Posts: 7

    you should use string instead. I will post the full answer tomorrow cause I'm too busy now

  • StupidKidStupidKid VietnamMember Posts: 7

    this function is quite hard to understand so you should read it carefully. in this function, "Add" is a function to plus two numbers in string. It's easy so you can write it yourself.

    Function multiply(a,b : string): string;
    Var sum,temp : string;
         m,i,j : integer;
    Begin
     m:=-1; sum:='';
     for i:=length(a) downto 1 do
       begin
         m:=m+1;
         tmp:='';
         for j:=1 to ord(a[i])-48 do tmp:=add(tmp,b);
         for j:=1 to m do tmp:=tmp+'0';
         sum:=add(tmp,sum);
       end;
     multiply:=sum;
    End;
Sign In or Register to comment.