Solved

Sum Of  two positive integers!

Posted on 2000-02-22
2
258 Views
Last Modified: 2010-04-16
Write a program to compute the sum of two positive integer numbers.  Each number is up to 20 digits.  Do not use any REAL or LONGINT types in the program.

Must use stacks, digits must be read in one-by-one.  For example 2345678 + 9999999999, must be read in 2, then 3, then 4, and so on.  if sum of two digits is greater than 9, u must carry it over, so the next part can use it.
0
Comment
Question by:hipopynonamous
2 Comments
 
LVL 2

Expert Comment

by:kellyjj
ID: 2547666
We can't do your homework for you.  Try it yourself, and then post the code you are having probs w/.
0
 
LVL 3

Accepted Solution

by:
Alisher_N earned 100 total points
ID: 2547677
var
   s1,s2,s3 : String;
   j,j1,j2,j3,max,carry1 : Byte;
begin
  Write( 'enter first number: ' );
  Readln( s1 );
  Write( 'enter second number: ' );
  Readln( s2 );

  max := Length( s1 );
  if max < Length( s2 ) then max := Length( s2 );
  while Length( s1 ) < max do s1 := '0' + s1;
  while Length( s2 ) < max do s2 := '0' + s2;
  carry1 := 0; s3 := 0;
  for j := max downto 1 do begin
    j1 := Ord( s1[j] ) - $30; {ASCII -> value }
    j2 := Ord( s2[j] ) - $30;
    j3 := j1 + j2 + carry1;
    carry1 := j3 div 10;
    j3 := j3 mod 10 + $30;
    s3 := Chr( j3) + s3;
  end; {for}
  if carry1 = 1 then s3 := '1' + s3;
  writeln( 'result: ', s3 );
end.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question