[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sum Of  two positive integers!

Posted on 2000-02-22
2
Medium Priority
?
280 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 300 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Social messanging services like WhatsApp and Facebook can help businesses in ways that many owners don't even imagine, giving new opportunities to connect with customers. Discover some of the most innovative things they can do for your company.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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