Solved

Sum Of  two positive integers!

Posted on 2000-02-22
2
242 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Search the database TADOQuery and TVirtualStringTree 3 613
Client dataset dumping records on set of IndexName 4 483
Real time Change DisplayName of service 7 603
WebCam and Delphi 2 2,553
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

948 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now