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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.