Solved

Sum Of  two positive integers!

Posted on 2000-02-22
2
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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