Multiplying two large numbers in Turbo Pascal - Programmers Heaven

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 iranPosts: 1Member

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 VietnamPosts: 7Member

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

  • StupidKidStupidKid VietnamPosts: 7Member

    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.